for文
for (let i = 0; i < 10; i++) {
console.log(i)
}
実行結果
0
1
2
3
4
5
6
7
8
9
for-break
for(let i = 0; i < 10; i++) {
console.log(i)
if (i == 8) {
break
}
}
実行結果
0
1
2
3
4
5
6
7
8
for-continue
for(let i = 0; i < 10; i++) {
if (i % 2 == 0) {
continue
}
console.log(i)
}
実行結果
1
3
5
7
9
for-in
let array = {
variable_01 = "value_01",
variable_02 = "value_02",
variable_03 = "value_03"
}
for (var val in array) {
console.log(val)
}
実行結果
value_01
value_02
value_03
for-of
let array = [1, 2, 3, 4, 5]
for (var val of array) {
console.log(val)
}
実行結果
1
2
3
4
5