1# 配列の長さぶん処理をするときには
ForIn ではなく ForEach を使おう!
fruits.forEach(function(item, index, array) { console.log(item, index); }); // りんご 0 // バナナ 1
→indexも実は使える…
for(let i in fruits){ console.log(fruits[i],i); // りんご 0 // バナナ 1 /* 一見こっちの方が簡単にすませられそうだが、 */ console.log(typeof i ,i+1); // string,NaN // string,NaN /* Indexが文字列なので計算できなかったり… */
}
なので、forinを使う