1.find是获取指定的数组项
var standardOption: [
{ name: "实际出勤天数", code: "1" },
{ name: "外勤打卡天数", code: "2" },
{ name: "出差天数", code: "3 " },
{ name: "外出次数", code: "4" },
],
对数组standardOption使用find
let obj = {};
obj = this.standardOption.find(function (item) {
return item.code === e;
});
console.log(obj) // { name: "实际出勤天数", code: "1" }
obj .lzl= 100
console.log(obj )//{ name: "实际出勤天数", code: "1" , lzl:100 }
console.log(standardOption)
/*
[
{ name: "实际出勤天数", code: "1" , lzl:100 },
{ name: "外勤打卡天数", code: "2" },
{ name: "出差天数", code: "3 " },
{ name: "外出次数", code: "4" },
]
*/
2.filter是用于对数组过滤
var arr = [2,5,9,6,74,1,59,64,34,452];
对数组arr使用filter
let obj = arr.filter(item =>{
return item > 10
})
console.log(obj);//[74,59,64,34,452]