去除数组中重复元素

var arr=["a","b","c","a","a","b","d"];
    function fn(array){
        var newArr=[];
        for(var i=0;i<array.length;i++){
            var bool=true;
            for(var j=0;j<newArr.length;j++){
                if(array[i]===newArr[j]){
                    bool=false;
                }
            }
            if(bool){
                newArr[newArr.length]=array[i];
            }
        }
        return newArr;
    }
    console.log(fn(arr));    // ["a", "b", "c", "d"]

 

posted @ 2017-09-06 12:26  asimpleday  阅读(194)  评论(0编辑  收藏  举报