标签:数组去重 div pre sort fun style == ret func
1 var c=[1,8,6,4,88,22,99,4,6,86,5,58,89,5]; 2 c.sort(function (a,b) { 3 return a-b;//从小到大排序 改变原数组 4 }); 5 c = unique(c); 6 function unique(arr){ 7 var res = [arr[0]]; 8 for(var i=1;i<arr.length;i++){ 9 if(arr[i] !== res[res.length-1]){ 10 res.push(arr[i]); 11 } 12 }; 13 return res; 14 };
var a= [1,2,23,4],
b = [2,2,5,6,7];
var d=a.concat(b);//a在前 生成新数组
标签:数组去重 div pre sort fun style == ret func
原文地址:http://www.cnblogs.com/-maomao-/p/7599635.html