共计 514 个字符,预计需要花费 2 分钟才能阅读完成。
// 上一次的数据,旧数组
var oldArray = [{ id: '1', name: 'zhangsan', age: '15'},
{id: '2', name: 'lisi', age: '16'},
{id: '3', name: 'ani', age: '17'},
]
// 刚刚返回的新数组
var newArray = [{ id: '1', name: 'zhangsan', age: '100'},
{id: '2', name: 'lisi'},
]
// 将旧数组过滤出符合条件的数据 id 汇合
const idsArray = oldArray.filter((item) => {return item.id !== '1'}).map((item) => {return item.id});
console.log(idsArray, 'idsArray');
// ['2', '3'] 'idsArray'
const productList = newArray.filter((item) => {return idsArray.includes(item.id)
})
console.log(productList, 'productList')
// [{id: '2', name: 'lisi'}] 'productList'
正文完
发表至: javascript
2022-10-15