标签:
js 数组去重 方法(新建数组存储)
function getnotchongArray(a){ var hash = {}, len = a.length, newarry = []; for(var i=0;i<len;i++){ if(!hash[a[i]]){ hash[a[i]] = true; newarry .push(a[i]); } } return newarry; } var arr = [1,2,3,2,1,2,3,4,5,2,2,3,1]; getnotchongArray(arr)
js 数组去空去重的方法
1 function iskongarray(a){ 2 var newarray = [], 3 json = {}; 4 for(var i=0;i<a.length;i++){ 5 if(a[i] == ‘‘){ 6 continue; 7 }else{ 8 if(!json[a[i]]){ 9 newarray.push(a[i]); 10 json[a[i]] = true; 11 } 12 } 13 } 14 newarray.sort(); 15 return newarray; 16 }; 17 var arr = [‘‘,‘‘,1,3,4,‘adb‘,‘fee‘,‘sss‘,43,3,2,2,3,1]; 18 console.log(iskongarray(arr));//[ 1, 2, 3, 4, 43, ‘adb‘, ‘fee‘, ‘sss‘ ]
标签:
原文地址:http://www.cnblogs.com/zerohu/p/5498751.html