lodash去重:
1.引入
import _ from ‘lodash‘;
2.代码:[此处以id来作为去重的判断]
let data = [...arrA, ...arrB]; data = _.uniqBy(data, ‘id‘); console.log(data)
取差集:
[生成一个arrA中不存在arrB中所有元素的数组]
const { arrA, arrB} = this.state; const checkedId = arrB&& arrB.map((item: any) => item.id) const restList = arrA.filter((item: any) => checkedId.indexOf(item.id) === -1) || []