VUE对数组中的Object对象进行去重处理

VUE对数组中的Object对象进行去重处理

数组

driverList = [
	{
		driverName: '张三',
		age: 20
	},
	{
		driverName: '李四',
		age: 20
	},
	{
		driverName: '张三',
		age: 20
	},
]

根据name去重处理

let obj = {};
this.driverList = this.driverList.reduce((cur, next) => {
  obj[next.driverName] ? '' : (obj[next.driverName] = true && cur.push(next));
  return cur;
}, []);

你可能感兴趣的:(vue,vue.js,javascript,前端)