if 判断
var age1 = 3;
if (age1>5){console.log("da3")
}else if (age1>2){console.log("da2")
}else {console.log("else")
}
while循环
while (age1<20){age1 = age1 + 1console.log(age1)
}
// do while 最少执行一次
do{age1 = age1 + 1console.log(age1)
}while (age1<20)
for循环
idea快捷 fori
for (let i = 0; i < 20; i++) {console.log(i)
}
forEach 循环
var arr2 = [1,2,5,4,3]
arr2.forEach(function (value, index, array) {console.log(value)console.log(index)console.log(array)
})
arr2.forEach(function (value, index) {console.log(value)console.log(index)
})
arr2.forEach(function (value) {console.log(value)
})
for in
var arr2 = [1,2,5,4,3]
for (var num in arr2) {if (arr2.hasOwnProperty(num)){console.log("存在")console.log(num)console.log(arr2[num])}
}
for of
var arr2 = [1,2,5,4,3]
for (let number of arr2) {console.log(number)
}
更详细内容可参考:
https://wangxiaomu.blog.csdn.net/article/details/78444088
https://blog.csdn.net/w390058785/article/details/80522383
https://blog.csdn.net/fu983531588/article/details/89597521
https://www.bilibili.com/video/BV1JJ41177di?p=9