首页 > 其他分享 >js数组去重

js数组去重

时间:2022-09-20 18:13:28浏览次数:49  
标签:tmp index function tmpArr js item 数组

根据数组对象中某个属性去重

let newTags = tags.reduce(function (tmpArr, item) {
        if (tmpArr.findIndex((tmp) => tmp.name === item.name) === -1) {
          tmpArr.push(item)
        }
        return tmpArr
      }, [])

根据数组中元素去重

let newList = list.filter(function (item, index) {
        return list.indexOf(item) === index
      })

标签:tmp,index,function,tmpArr,js,item,数组
From: https://www.cnblogs.com/sglblog/p/16695637.html

相关文章