■for文・・・配列の要素を順に取り出す
const animals = ["dog", "cat", "sheep"];
for(let i=0; i<3; i++)
iが0~2の間ループする
{ console.log(animals[i]);}
変数iを用いて要素を取得
dog
cat
sheep
■length・・・配列の要素数を取得
const animals = ["dog", "cat", "sheep"];
console.log(animals.length);
3
■length・・・配列の要素を順に取り出す
配列の要素数が変わっても繰り返すことができる
const animals = ["dog", "cat", "sheep"];
for(let i=0; i<animals.length; i++)
{ console.log(animals[i]);}
変数iを用いて要素を取得
dog
cat
sheep