数组去重

 

 

 

var testarr = [11,2,6,31,31,31,31,11,2,5]

// 数组去重
function deleteSome(arr) {
    var newarr = []
    arr.map((item)=>{
        if(newarr.indexOf(item) < 0) {
            newarr.push(item)
        }
    })
    return newarr
}

var afterDelete = deleteSome(testarr)
console.log(afterDelete)    // [11, 2, 6, 31, 5]

 

posted @ 2019-11-01 11:06  牧羊狼  阅读(144)  评论(0编辑  收藏  举报