json格式下的数组去重

Posted 10后程序员劝退师

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json格式下的数组去重相关的知识,希望对你有一定的参考价值。

    var users = [{
      id: 1, name: "a"
    }, {
      id: 2, name: "a"
    }, {
      id: 3, name: "b"
    }, {
      id: 4, name: "v"
    }]
    Array.prototype.unique = function () {
      var res;
      var arr = this.map(item => {
        return this[item.id - 1] = item.name
      })
      // ES6里新添加了两个很好用的东西,set和Array.from
      // set是一种新的数据结构,它可以接收一个数组或者是类数组对象,自动去重其中的重复项目。
      res = new Set(this);
      console.log("new Set对象", res)
      res = Array.from(new Set(this));
      return res//es6 数组去重
    }
    console.log(users.unique());
  },

 

以上是关于json格式下的数组去重的主要内容,如果未能解决你的问题,请参考以下文章

怎么对数组中的对象去重

C/C++系列数组去重代码实现

C/C++系列数组去重代码实现

C/C++系列数组去重代码实现

c两个数组合并去重

js实现数组排序并去重