标签:font color 遍历 下标 strong code let class javascrip
1.遍历数组:
let arr = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘]; for(let i=0;i<arr.length;i++){ console.log(arr[i]); }
2.遍历数组中的每一个值:
例: let arr = ["A"]
let arr =["A","B","C","D","E"]; for (let item of arr){console.log(item)} 输出结果:["A","B","C","D","E"]
3.遍历出数组中每个值的下标:
let arr = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘];
for(let item in arr){
console.log(item);
}
输出结果:[0,1,2,3,4,5]
ES6新增
let arr = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘];
for(let item in arr){ console.log(item);
}
输出结果:[0,1,2,3,4,5]
let arr = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘];
for(let item of arr.values()){
console.log(item);}
输出结果:["A","B","C","D","E","F"]
let arr = [‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘, ‘F‘];
for(let item of arr.entries()){ console.log(item); }
输出结果:[ 0, ‘A‘ ][ 1, ‘B‘ ][ 2, ‘C‘ ][ 3, ‘D‘ ][ 4, ‘E‘ ][ 5, ‘F‘ ]
标签:font color 遍历 下标 strong code let class javascrip
原文地址:https://www.cnblogs.com/sunhaobin/p/12180247.html