js数组对象去重
程序员文章站
2022-06-24 14:38:00
转: https://www.cnblogs.com/gaoht/p/9850449.html 在数组对象中去掉重复的对象: eg: ......
转:
在数组对象中去掉重复的对象:
export function deteleobject(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; } } uniques = uniques; return uniques; }
eg: