例如有这样一个JSON,想要去掉重复项。{"i1":"1231", "i2":"9387", "i3":"68433", "i4":"1231", "i5":"43566"}i1和i4的值相等,重复了,如何去重呢?
1 回答
红糖糍粑
TA贡献1815条经验 获得超6个赞
跟数组一样的
var _json = {"i1":"1231", "i2":"9387", "i3":"68433", "i4":"1231", "i5":"43566"};
var newJson = {};
for(var key in _json){
if(newJson[_json[key]]){
delete _json[key];
}else{
newJson[_json[key]] = true;
}
}
console.log(_json)
添加回答
举报
0/150
提交
取消