6
3

More than 1 year has passed since last update.

javascriptで文字列を掛け算する方法

Posted at

概要

Javascriptで同じ文字列を掛け算して羅列する際に、Rubyとは記載方法が異なったためメモとして残しておきます。

記載方法

Rubyの場合

puts 'a' * 3
#=> aaa

Rubyの場合は単純に文字列に数字を掛ければ求められる。

Javascriptの場合

console.log('a'.repeat(3))
//=> aaa

Javascriptの場合はRubyのように単純な計算式ではなく、repeatメソッドを使います。

6
3
0

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
6
3