根据某个参数进行去重
// 以x进行去重
import _ from 'lodash'
const list = [{ 'x': 1,'y':2 }, { 'x': 2,'y':2 }, { 'x': 1,'y':2 },{ 'x': 2,'y':1 }]
console.log(_.uniqBy(list, 'x'))
// [{ "x": 1, "y": 2}, { "x": 2, "y": 2 }]
根据多个参数进行去重
// 以x,y进行去重
import _ from 'lodash'
const iteratee = (item) => {
return item.x + '|' + item.y;
};
const list = [{ 'x': 1,'y':2 }, { 'x': 2,'y':2 }, { 'x': 1,'y':2 },{ 'x': 2,'y':1 }]
console.log(_.uniqBy(list, iteratee))
//[{"x": 1,"y": 2}, {"x": 2, "y": 2},{"x": 2,"y": 1}]
更多好用的方法有兴趣的可以去学学
lodash官网