美文网首页
js数组去重加数组过滤

js数组去重加数组过滤

作者: xiaoaiai | 来源:发表于2018-01-09 16:20 被阅读0次
    const arrSync = [30, 20, 50, 20, 30]
    //数组去重
    const newArrSync = arrSync.filter((ele, index, arr) => arr.indexOf(ele) == index)
    const arr = [
        {text: '新建10', value: 10},
        {text: '新建20', value: 20},
        {text: '新建30', value: 30},
        {text: '新建40', value: 40},
        {text: '新建50', value: 50},
        {text: '新建60', value: 60}
    ]
    let aa = []
    arrSync.map(item => {
        aa.push(arr.filter(items => items.value == item)[0])
        return item
    })
    //          console.log(aa)
    
    function newArr (newArrs = [], arrs = []) {
        let arr = []
        newArrs.filter((item, index, arr) => arr.indexOf(item) === index)
        newArrs.map(item => {
            arr.push(arrs.filter(items => items.value == item)[0])
            return item
        })
        return arr
    }
    console.log(newArr(arrSync, arr))
    

    相关文章

      网友评论

          本文标题:js数组去重加数组过滤

          本文链接:https://www.haomeiwen.com/subject/wqhgnxtx.html