js去重合并

1.去重

for(var q = 0;q<jsonArr.length;q++){
 
for(var e=0;e<jsonArr[q].data.length;e++){
 
var matchCode = jsonArr[q].data[e];
var chua = jsonArr[q].jsonObj;
var isExist = false;
var isC = false;
//去重多少场次
for(var m = 0; m < an.length; m ++){
 
if(jsonArr[q].data[e].mhcode == an[m].mhcode && jsonArr[q].data[e].jackpot==an[m].jackpot &&
jsonArr[q].data[e].option == an[m].option){
isExist = true;
break;
}
}
//去重几串几
for(var r=0;r<jso.length;r++){
if(jsonArr[q].jsonObj.e0 == jso[r].e0 && jsonArr[q].jsonObj.e1 == jso[r].e1){
 
isC = true;
break;
}
}
if(!isExist){
an.push(matchCode);
}
if(!isC){
jso.push(chua);
}
 
}
}
 
2合并
var s = new Array();
for(var e=0;e<an.length;e++){
var matchCode = an[e];
 
var isExist = false;
for(var m = 0; m < s.length; m ++){
if(matchCode.mhcode == s[m].mhcode && matchCode.jackpot==s[m].jackpot ){
s[m].option +=","+matchCode.option;
isExist = true;
break;
}

}
if(!isExist){
s.push(matchCode);
 
}
}
3.分组
var map = {},
dest = [];
 
for(var i = 0; i < s.length; i++){
var ai = s[i];
 
if(!map[ai.mhcode]){
dest.push({
mhcode: ai.mhcode,
jk:ai.jackpot,
 
data: [ai]
});
map[ai.mhcode] = ai;
}else{
for(var j = 0; j < dest.length; j++){
var dj = dest[j];
if(dj.mhcode == ai.mhcode ){
dj.data.push(ai);
break;
}
}
}
}

posted on 2018-03-13 20:42  xingzhukang  阅读(1110)  评论(0编辑  收藏  举报

导航