arrUnique:function(arr){ //传入空数组的时候有bug,length会变成1 所以修复下 if(arr.length == 0){ return []; } arr.sort(function compare(a,b){return a-b;}); //先排序 var res = [arr[0]]; for(var i = 1; i < arr.length; i++){ if(arr[i] !== res[res.length - 1]){ res.push(arr[i]); } } return res; }
不过看了下大牛的去重方法,好像都不是这样做的,可以参考这个地址:
http://blog.csdn.net/chengxuyuan20100425/article/details/8497277
The most hurt is day after day ,I find that myself is still myself.