const lists = [2, 4, 1, 8, 7, 3, 5]
常用在印字串。若為for…in 是印索引值。
for (xx of lists) {
console.log(xx);
}
for (let i = 0; i < lists.length; i++) {
console.log(lists[i]);
}
lists.forEach( (el) => {
console.log(el);
})
let i = 2
let j = i++
console.log(i) => 3 // 先不要管j,把i++獨立出來看,所以 = 3
console.log(j) => 2 // 先把i指給j,再做i++
let i = 2
let j = ++i
console.log(i) => 3 // 先不要管j,把i++獨立出來看,所以 = 3
console.log(j) => 3 // 先做++i,再把i指給j
for (var i = 1; i < 10; i++) {
if (i == 4 || i == 6) {
continue;
}
console.log(i)
}
for (var i = 1; i < 10; i++) {
if (i == 4) {
break;
}
console.log(i)
}