0
0

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 3 years have passed since last update.

配列とループ分

Posted at

case

  • lengthは要素数を評価
  • arry2のように途中で"0"= falsyな値があると途中でループが止まる。

const arry = [1, 2, 3, 4, 5];
const arry2 = [1, 2, 3, 0, 5];

for(let i = 0; i < arry.length; i++){
    console.log(i)
}

>>> 1
>>> 2
>>> 3
>>> 4
>>> 5

case2

  • [i++]後方インクリメントは初期値を代入してから+1されるので最初のループはvに0が渡されている。
  • arry配列5以上場合はundifindが戻り値になるのでfalseになりループが止まる

let v, i = 0 //pythonはたしかこのような変数宣言は推奨されていなかったきがする。

while(v = arry[i++]){
    console.log(v);
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?