→
その String を指定数だけコピーして結合した文字列を返します。
String | String。 |
---|---|
count | 0 から正の無限大までの間の整数で、文字列を繰り返す数を示します。 |
String。与えられた文字列の指定した回数分のコピーを含む新しい文字列です。
D='abc'.repeat(-1); // RangeError発生 D='abc'.repeat(0); //='' D='abc'.repeat(1); //='abc' D='abc'.repeat(2); //='abcabc' D='abc'.repeat(3.5); //='abcabcabc'。小数は丸められ、整数の結果が返されます。 D='abc'.repeat(1/0); // RangeError発生 D=({ toString: () => 'abc', repeat: String.prototype.repeat }).repeat(2); //='abcabc'。repeat() は汎用メソッドです。