calamus
calamus
冬天从这里夺去的,春天会交还与你。

 

1.对象数组去重

let hash = {}
    let config = [{
            id: 2,
            name: 'Y',
        }, {
            id: 3,
            name: 'A',
        }, {
            id: 5,
            name: 'S',
        }]
const newArr = config.reduceRight((item, next) => {
        hash[next.id] ? '' : hash[next.id] = true && item.push(next)
        return item
    }, [])
console.log(item)

2.字符串数组去重
 1.es6方法

let array = [1,2,3,4,5]
array = Array.from(new Set(array));
 console.log(array)

 2.其他方法

 

//方法1

let arr = [1,2,3,1,'a',1,'a']

arr.filter(function(ele,index,array){ return index===array.indexOf(ele) })

 

posted on 2019-04-02 17:57  calamus  阅读(838)  评论(0编辑  收藏  举报