我有一个包含对象数组的对象。
obj = {}; obj.arr = new Array(); obj.arr.push({place:"here",name:"stuff"}); obj.arr.push({place:"there",name:"morestuff"}); obj.arr.push({place:"there",name:"morestuff"});
我想知道从数组中删除重复对象的最佳方法是什么。因此,例如,obj.arr将成为…
obj.arr
{place:"here",name:"stuff"}, {place:"there",name:"morestuff"}
一个原始的方法是:
const obj = {}; for (let i = 0, len = things.thing.length; i < len; i++) { obj[things.thing[i]['place']] = things.thing[i]; } things.thing = new Array(); for (const key in obj) { things.thing.push(obj[key]); }