LoginSignup
0
0

More than 3 years have passed since last update.

気づいたこと日記(1日目)

Last updated at Posted at 2020-01-23

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を使う

0
0
1

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