趁着年轻丶去疯狂吧
2015-11-02 08:11
采纳率: 50%
浏览 3.6k
已采纳

Js或者Jquery对Json数组进行去重

var arr = [
{"name" : "1","value" : "qqq","age" : "10"},
{"name" : "1","value" : "qqq","age" : "10"},
{"name" : "2","value" : "eee","age" : "20"},
{"name" : "4","value" : "rrr","age" : "50"},
{"name" : "5","value" : "ttt","age" : "100"}
];
除去重复数据,name value age 三个值均相等为重复数据,求大神帮忙

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    
        var arr = [
    { "name": "1", "value": "qqq", "age": "10" },
    { "name": "1", "value": "qqq", "age": "10" },
    { "name": "1", "value": "qqq", "age": "10" },
    { "name": "2", "value": "eee", "age": "20" },
    { "name": "4", "value": "rrr", "age": "50" },
    { "name": "5", "value": "ttt", "age": "100" }
        ];
        for (var i = 0; i < arr.length; i++) {
            for (var j =i+1; j <arr.length; ) {
                if (arr[i].name == arr[j].name && arr[i].value == arr[j].value && arr[i].age == arr[j].age) {
                    arr.splice(j, 1);
                }
                else j++;
            }
        }
        console.log(arr)
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • code_txy 2019-01-30 17:14

    for (var i = 0; i < arr.length; i++) {
    for (var j =i+1; j <arr.length; ) {
    if (arr[i].name == arr[j].name && arr[i].value == arr[j].value && arr[i].age == arr[j].age) {
    arr.splice(j, 1);
    }
    else j++;
    }
    }
    console.log(arr)

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题