遍历数组

JavaScript中遍历数组的方法:

一、for in:遍历数组中每一个值或 下标

例:let arr = ["we", "as", "vf"];

for (let i in arr) {

console.log(arr[i]); }

二、for of:遍历数组中每个值

例:for (let i of arr.keys() )

{ console.log(i); }

三、常见的一种就是使用for循环直接遍历

ES6新增遍历数组的方法:

一、keys()   遍历出数组每个值的键(下标)

例:for(let itme of arr.keys()){

console.log(itme ); }

二、 values()  遍历数组中的每一个值

例:for(let itme of arr.values()){

console.log(itme );

}

三、entries()遍历数组中每个值,以及每个值相对应的键(下标)

例:for(let itme of arr.entries()){

console.log(itme );

}

以上就是遍历JS中遍历数组的几种方法!

 

posted on 2020-01-12 04:11  ~sun  阅读(109)  评论(0)    收藏  举报

导航