一个简单的数组对象去重,方便cv

2021-12-06  本文已影响0人  zhang_sir_

// 数组去重 arr:数组;key:根据数组中为key的键名去重

    filterArr(arr, key) {

      const hash = {};

      return arr.reduce((ss, item) => {

        hash[item[key]] ? '' : (hash[item[key]] = true && ss.push(item));

        return ss;

      }, []);

    },

上一篇 下一篇

猜你喜欢

热点阅读