去除重复的方式

Array.prototype.noRepeated=function(){  

var newArray=[], flags={};

for (var i=0;i<this.length;i++){    

   
var item= this[i];

   
if (!flags[item]) {  
   
    newArray.push(item);  
   
    flags[item]
= true;  
   
    }  
}  

return newArray;  

}


var a={"a":"0","b":"OK","c":[{"Account":"81614031","Time":"2012-11-26"},{"Account":"81614031","Time":"2012-11-26"}]}

var cItems=a.c;
var sourceArray= [];
$(cItems).each(function(index){
   
    sourceArray.push(cItems[index].Account)
   
});

sourceArray
=sourceArray.noRepeated();
alert(sourceArray.join(",")); 

=============================

var json_data=a;
var data={};
for(var i=0; i<json_data.c.length; i++){
  data[json_data.c[i].Account]
="";
}
var result="";
for(var p in data){
if(result==""){
result
=p;
}
else{
  result+=","+p;
  }
}
alert(result);

 

posted @ 2013-02-26 15:46  Yu  阅读(189)  评论(0编辑  收藏  举报