代码如下:
var result = [];
var hash = {};
var hash_ = {};
var fileLists = [{filename: "登记icon.png",url:a},{filename: "审核icon.png",url:b},,{filename: "反馈icon.png",url:c}];
var obj = {filename: "审核icon.png",url:d};
fileLists.push(obj);
for(var i = 0; i < fileLists.length; i++) {
var elem = fileLists[i].filename;
var elem_ = fileLists[i].url;
if(!hash[elem]) {
if(!hash_[elem_]) {
result.push(fileLists[i]);
hash_[elem_] = true;
};
hash[elem] = true;
}
}
console.log(result )
//结果是:[{filename: "登记icon.png",url:a},{filename: "审核icon.png",url:b},,{filename: "审核icon.png",url:c}]
数组对象去重每次都是保留数组下标靠前的对象,我想把新增的对象覆盖原来的对象该怎么做?