首页 > 代码库 > js 数组去重

js 数组去重

        //数组去重        Array.prototype.unique5 = function() {            var res = [], hash = {};            for(var i=0, elem; (elem = this[i]) != null; i++)  {                if (!hash[elem]) {                    res.push(elem);                    hash[elem] = true;                }            }            return res;        }        var arr=[1,2,3,4,5,6,7,2,3,4,2,5];        alert(arr.unique5());

 

js 数组去重