js 数组对象去重

let hash = {};
    let config = [
      { name: 2, state: true, output: 'Y'}, 
      { name: 3, state: true, output: 'A'},
      { name: 5, state: true, output: 'S'},
      { name: 7, state: true, output: 'B'}
    ];
    config = [...config, { // 合并数组   ...运算符即为数组展开运算符
      name: 3,
      state: false,
      output: 'A',
    }]
    const newArr = config.reduce((item, next) => {
      console.log('hash--',hash)
      console.log('next--',next.name)
      console.log('hash[next.name]--',hash[next.name])
      hash[next.name] ? '' : hash[next.name] = true && item.push(next);
      return item
    }, []);
//[{"name":2,"state":true,"output":"Y"},{"name":3,"state":true,"output":"A"},{"name":5,"state":true,"output":"S"},{"name":7,"state":true,"output":"B"}]
原文地址:https://www.cnblogs.com/jsonYoung/p/10108245.html