两个数组对象根据其中一个数组对象判断另外一个是否存在,并创建一个新数组
// let arr1 = [{ di: 1, name: '张三' }, { di: 2, name: '张si' }, { di: 3, name: '张五' }];
// let arr2 = [{ name: '张三', value: 20 }, { name: '张五', value: 18 }];
arr1 .map(item => {
item.value = (0).toFixed(2);
item.isOpen = false;
});
let newarr1 = [...arr1 ];
arr2 .map(item1 => {
newarr1.map(item2 => {
if (item1.name === item2.name) {
item2.isOpen = true;
item2.value = item1.value;
return;
}
});
});
console.log(newarr1);
(3) [{…}, {…}, {…}]
0: {di: 1, name: “张三”, value: 20, isOpen: true}
1: {di: 2, name: “张si”, value: “0.00”, isOpen: false}
2: {di: 3, name: “张五”, value: 18, isOpen: true}