程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> json-Js或者Jquery對Json數組進行去重

json-Js或者Jquery對Json數組進行去重

編輯:編程綜合問答
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 三個值均相等為重復數據,求大神幫忙

最佳回答:



    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)
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved