编辑代码

//JSRUN引擎2.0,支持多达30种语言在线运行,全仿真在线交互输入输出。
let ls = [
    {
        name:'1',
        id:'2'
    },
        {
        name:'2',
        id:'2'
    },
        {
        name:'1',
        id:'3'
    },
       {
        name:'2',
        id:'3'
    },
] 
//根据key对数组去重 
const deduplication= (arr, key)=>{
    let res = []
    arr.forEach((item) => {
      let list = []
      res.forEach((resitem) => {
        list.push(resitem[key])
      })
      if (list.indexOf(item[key]) === -1) {
        res.push(item)
      }
    })
    return res
  }

console.log( deduplication(ls,'name') );