一、安装插件

命令:  npm install dedupe 或者 yarn add dedupe

参考网站: https://www.npmjs.com/package/dedupe

二、代码例子

eg: 1.数组形式去重如下

var list = [1, 2, 2, 3]
var dedupe = require('dedupe')
var result = dedupe(list)
console.log(result)
//result: [1, 2, 3]

eg: 2:普通数组对象去重

var dedupe = require('dedupe')
var list= [{value: 2}, {value: 1}, {value: 1}, {value: 1}]
var result= dedupe(list)
console.log(result)
//result: [{value: 2}, {value: 1}]

eg: 3.复杂数组对象形式去重,如下↓,我们通过工具去除重复的value为测试1的对象。

list=[
        id:1,
        value:测试1,
        label:测试1,
        id:2,
        value:测试2,
        label:测试2,
        id:3,
        value:测试1,
        label:测试1,
]

CommonTool.js 工具

const dedupe = require('dedupe')
export default class CommonTool {
//去除重复数组对象某个重复值
export const removesDuplicates=(array,duplicatesValue)=> {
  return array = dedupe(array, duplicatesValue => duplicatesValue.value)
};

去除value只需要

list=removesDuplicates(list,list.value);
 list= dedupe(list, list.value=> list.value)