循环数组
let arr = [1, 2, 3, 4, 5, 6, 7, 8]
//1
//2
//3
//4
//5
//6
//7
//8
// for
for (var i = 0; i < arr.length; i++) {
console.log('arr[i]===', arr[i], "===", i);
}
console.log('==========',);
//map filter same every find forEach
console.log('==========',);
// for in
let arrObj = [{
name: 'zjq',
age: 18
}, {
name: 'zrh',
age: 188
}, {
name: 'zzz',
age: 1888
}, {
name: 'hhh',
age: 18888
}, {
name: 'qqq',
age: 188888
},]
for (let i = 0; i < 5; i++) {
console.log('arrObj[i]===', arrObj[i]);
}
console.log('==========',);
// for in
for (let key in arrObj) {
console.log('obj[key]===', arrObj[key], "===key", key);
}
//
for (let key of arrObj) {
console.log('arrObj===', arrObj, "===key", key);
}
for: 数组[下标]
for…of:key 每一项
for…in key下标
循环对象
let obj = {
name: 'zjq', age: 18, habby: '123456', 0: 123 }
console.log('==========',);
for (let key in obj) {
console.log('obj[key]===', obj[key], "===key", key);
}
for…in:key键值 对象[key]键值的value