码迷,mamicode.com
首页 > Web开发 > 详细

给json对象去除重复的值

时间:2018-06-12 23:30:28      阅读:334      评论:0      收藏:0      [点我收藏+]

标签:cti   fun   prot   lse   json对象   turn   custom   array   ===   

给数组去除重复值

Array.prototype.distinct = function() {
var arr = this,
result = [],
i,
j,
len = arr.length;
for (i = 0; i < len; i++) {
for (j = i + 1; j < len; j++) {
if (arr[i] === arr[j]) {
j = ++i;
}
}
result.push(arr[i]);
}
return result;
}

2.给json数组对象去除重复值

for (var i = 0; i < customerIds.length; i++) {
for (var j = i + 1; j < customerIds.length;) {
if (customerIds[i].code == customerIds[j].code && customerIds[i].shootOn == customerIds[j].shootOn && customerIds[i].siteId == customerIds[j].siteId && customerIds[i].cardBagPPUrl == customerIds[j].cardBagPPUrl) {
customerIds.splice(j, 1)
} else j++
}
}

 

给json对象去除重复的值

标签:cti   fun   prot   lse   json对象   turn   custom   array   ===   

原文地址:https://www.cnblogs.com/qiyc/p/9175515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!