recherche

Maison  >  Questions et réponses  >  le corps du texte

javascript - 怎么理解new Array(count + 1).join(this)

重复字符串方法

 String.prototype.repeat = function(count) {
      return new Array(count + 1).join(this);
    };

'test'.repeat(3);//testtesttest

巴扎黑巴扎黑2897 Il y a quelques jours317

répondre à tous(1)je répondrai

  • 巴扎黑

    巴扎黑2017-04-10 13:14:15

    一个长度为n+1的空数组用string去拼接成字符串,不就成了nstring的重复了么

    répondre
    0
  • Annulerrépondre