LoginSignup
1
0

More than 5 years have passed since last update.

配列の内容を繰り返し文で表示

Last updated at Posted at 2019-04-11

コード

ES5まで

for文で作った連続する数値を配列のインデックス(添字)として使う。

var tsuna = ['クロ','ミナミ','メバチ','キハダ','ビンナガ'];
for(var cnt=0; cnt<5; cnt++){
    console.log(tsuna[cnt] + 'マグロ');
}

ES2015

配列に所属する要素を変数に入れていく。
for(let 変数 of 配列)

let fish = ['クロ','ミナミ','メバチ','キハダ','ビンナガ'];
for(let tsuna of fish){
    console.log(tsuna + 'マグロ');
}

参考

ふりがなプログラミング

1
0
2

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
1
0