52
50

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.

javascriptで変数名を動的に生成・連結する方法

Posted at

概要

javascriptで動的に変数名を作成・宣言したい時,例えばfor文で次々に変数を作成・宣言したい時の方法.

生成・連結方法

  • evalを利用する.以下,num0~num9を動的に宣言し,初期化する例.

for (var i = 0; i < 10; i++) {
  eval("var num" + i + "=" + i + ";");
}
52
50
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
52
50

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?