1、查找数组中是否存在:some
var result = list.some(item=>{
if(item.id == '5'){
return 1;
}
});
2、查找所在下标:findIndex
var index = list.findIndex(e => e.id == '5');
3、删除指定对象(根据下标):splice
list.splice(index, 1);
4、返回一新数组:map
map() 方法返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值。
map() 方法按照原始数组元素顺序依次处理元素。
var newlist = list .map(function (item) {
return item.id;
});
5、查找符合条件对象:find
newArrar = this.array.find((item) => {
if(item.name === 'sisi'){
return item
}
})
//此时 newArray = {name:'sisi',age:18}
6、查找符合条件组成新数组:filter
var arr = [1, 2, 4, 5, 6, 9, 10, 15];
var r = arr.filter(function (x) {
return x % 2 !== 0;
});
// 此时r:[1, 5, 9, 15]