Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

6
3

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 3 years have 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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?