富贵资源网 Design By www.hznty.com
这篇文章主要介绍了JavaScript遍历数组的方法代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
for循环
let arr=["A","B","C","D","E","F"]; for(let i=0;i<arr.length;i++){ console.log(arr[i]); }
for...of
遍历出数组中的每个值
let arr=["A","B","C","D","E","F"]; for(let item of arr){ console.log(item); } //A B C D E F
for..in
遍历出数组中每个值的下标
let arr=["A","B","D","E","F"]; for(let item in arr){ console.log(item); } //0 1 2 3 4 5
ES6新增for...of的用法
遍历出数组中每个值的键(下标) arr.keys()
let arr=["A","B","C","D","E","F"]; for(let item of arr.keys()){ console.log(item); } //0 1 2 3 4 5
遍历出数组中的每个值 arr.values()
let arr=["A","B","C","D","E","F"]; for(let item of arr.values()){ console.log(item); } //A B C D E F
遍历出数组中的每个值,以及每个值对应的下标 arr.entries()
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' ] **/
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com
暂无评论...