62
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

同じ文字列を繰り返す

Last updated at Posted at 2014-06-27

(古い) 方法

Ruby の String#* みたいなことを JavaScript でもやりたい。

"Yuno" * 3 #=> "YunoYunoYuno"

Array()join() を使えばできます!

Array(3+1); //=> [undefined, undefined, undefined]
Array(3+1).join('Yuno'); //=> "YunoYunoYuno"

Stack Overflow でたまたま見つけたネタですが、目からうろこだったので。

現在の方法 (追記)

ES6 は String.prototype.repeat() を利用できます。

'Yuno'.repeat(3); //=> "YunoYunoYuno"

参考

62
46
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
62
46

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?