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))
every数组中每一个值都满足返回true,否者false
const arr = [4, 12, 16, 20];
var a = arr.every(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