js 去掉数组中重复的对象

function deteleObject(obj) {
// console.log(obj)
var uniques = [];
var stringify = {};
for (var i = 0; i < obj.length; i++) {
var keys = Object.keys(obj[i]);
keys.sort(function (a, b) {
return (Number(a) - Number(b));
});
var str = '';
for (var j = 0; j < keys.length; j++) {
str += JSON.stringify(keys[j]);
str += JSON.stringify(obj[i][keys[j]]);
}
if (!stringify.hasOwnProperty(str)) {
uniques.push(obj[i]);
stringify[str] = true;
}
}

app.uniques = uniques
return uniques
return uniques.length;
}

 

posted @ 2018-07-31 10:33  Faded露露  阅读(2980)  评论(0编辑  收藏  举报