给数组b里面的对象去重
b=[
{name:'A', age:'23'},
{name:'B', age:'33'},
{name:'A', age:'43'},
]
var a = {};
b= b.reduce(function(item, next) {
a[next.name] ? '' : a[next.name] = true && item.push(next);
return item
}, [])
最后得到的是
b=[
{name:'A', age:'23'},
{name:'B', age:'33'},
]
网友评论