我有一个包含对象数组的对象。
things = new Object(); things.thing = new Array(); things.thing.push({place:"here",name:"stuff"}); things.thing.push({place:"there",name:"morestuff"}); things.thing.push({place:"there",name:"morestuff"});
我想知道什么是从数组中删除重复对象的最佳方法。举例来说,事物……东西将变成……
{place:"here",name:"stuff"}, {place:"there",name:"morestuff"}
一种原始方法是:
var obj = {}; for ( var i=0, len=things.thing.length; i < len; i++ ) obj[things.thing[i]['place']] = things.thing[i]; things.thing = new Array(); for ( var key in obj ) things.thing.push(obj[key]);