数组去重
20170518更新
for (i = 0; i < obj4.length; i++) { for (j = 0; j < obj3.length; j++) { if (obj4[i].id == obj3[j].id) { obj3.splice(j, 1); } } }
用这种方法也是可以的,但是就是循环的次数会比continue的次数多
var totalList = [{ "id": 1, "name": "超级管理员", "type": 1, "privateToken": "Q1nz9HQoNbGpKsYw5XA2" }, { "id": 42, "name": "王淋", "type": 1, "privateToken": "MysZzsxwGGodc2w7BSNL" }, { "id": 44, "name": "张天佑", "type": 1, "privateToken": "Wgmv-5Ux8PfDCgxGfDoF" }, { "id": 53, "name": "叶华", "type": 1, "privateToken": "ASN7PxrAArUYYU6zarzJ" }, { "id": 55, "name": "张涛", "type": 1, "privateToken": "oryr7buVswnqdg2dyket" }, { "id": 60, "name": "qa", "type": 1, "privateToken": "u3sN5PJFsTMK_NLSsfDV" }, { "id": 65, "name": "朱纪超", "type": 1, "privateToken": "7R8ksr4rFssn1x3MgMti" }, { "id": 66, "name": "贺俊丽", "type": 1, "privateToken": "fYWW5JzBuUkicFXBT8Nh" }, { "id": 67, "name": "周玉红", "type": 1, "privateToken": "M7H4a_N88nczzxz4b2iR" }, { "id": 68, "name": "凌黎", "type": 1, "privateToken": "Ttfb7jGP8yrwsNLfvtTp" }, { "id": 76, "name": "樊玉琴", "type": 1, "privateToken": "sj1iuRxL4g8zdSwKxUCx" }, { "id": 78, "name": "陈国辉", "type": 1, "privateToken": "G-9v5SJEFYQnQ6edLoju" }]; for (n in totalList) { totalList[n].boo = false; } var testList = [{ "id": 42, "name": "王淋", "type": 1, "privateToken": "MysZzsxwGGodc2w7BSNL" }, { "id": 44, "name": "张天佑", "type": 1, "privateToken": "Wgmv-5Ux8PfDCgxGfDoF" }, { "id": 76, "name": "樊玉琴", "type": 1, "privateToken": "sj1iuRxL4g8zdSwKxUCx" }]; f1:for(var i=0,leni=testList.length;i<leni;i++){ for(var j=0;j<totalList.length;j++){ if(totalList[j].id==testList[i].id){ totalList.splice(j,1); j--; continue f1; } } } console.log(totalList);我写了好久,但是还是不太对,这个是诗瞻帮我写的