多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ### 1. `foreach` ~~~ var arr = [5,2,3,4]; arr.forEach(function(value,index){ console.log(index); }) ~~~ Jquery--each ~~~ var arr = [5,2,3,4]; $.each(arr,function(index,value){ console.log(index); }) ~~~ clone数组 ~~~ const items = ['item1', 'item2', 'item3']; const copy = []; for (let i=0; i<items.length; i++) { copy.push(items[i]) } ~~~ ~~~ const items = ['item1', 'item2', 'item3']; const copy = []; items.forEach(function(item){ copy.push(item) }); ~~~ ### 2.of ~~~ var arr = [5,2,3,4]; for(let value of arr){ console.log(value); } ~~~ ### 3.map ~~~ var arr = ["a","b","c","d"] var b= arr.map(item=>{ return item+"1" }) console.log(b); //a1,b1,c1,d1 ~~~ ### 4.some 只要一部分满足条件就返回true ~~~ const arr = [4, 12, 16, 20]; var a = arr.some(item => { return item > 18 }) //true console.log(a)) ~~~ ### 5.findIndex 遍历数组,获取满足条件的下标值 ``` const arr = [4, 12, 16, 20]; var a = arr.findIndex((item,index)=>{ return item>16 }) console.log(a) //3 ```