1利用reduce去重(数组对象)
// this.StaffHoursAllocationData 数组对象
    const obj1 = {}
       const peon = this.StaffHoursAllocationData.reduce((cur, next) => {
        obj1[next.idNumber] ? '' : obj1[next.idNumber] = true && cur.push(next)
        return cur
       }, [])
    console.log(peon)

 

 利用ES6 Set去重(ES6中最常用)
function unique (arr) {
  return Array.from(new Set(arr))
}
var arr = [1,1,'true','true',true,true,15,15,false,false, undefined,undefined, null,null, NaN, NaN,'NaN', 0, 0, 'a', 'a',{},{}];
console.log(unique(arr))
 //[1, "true", true, 15, false, undefined, null, NaN, "NaN", 0, "a", {}, {}]

 

 
第一种: 利用Map对象和数组的filter方法
    var arr1 = [1, 2, 3, 1, 2, 4, NaN, undefined, NaN, undefined]
    function unique(arr) {
      const res = new Map()
      return arr.filter((a) => !res.has(a) && res.set(a))
    }
    var newArr = unique(arr1)
    console.log(newArr);
结果:
1.Map对象是ES6提供的一个新的数据结构,其中has的办法是返回一个布尔值,表示某个值是否存在当前的Mp对象之中,set的办法是给Map对象设置key/value。
2.filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
所以说,Map对象结合filter方法可以达到数组去重的效果~
 
clear
    从映射中移除所有元素
delete
    从映射中移除指定的元素
forEach
    对映射中的每个元素执行指定操作
get
    返回映射中的指定元素
has
    如果映射包含指定元素,则返回 true
set
     添加一个新建元素到映射
toString
    返回映射的字符串表示形式
valueOf
    返回指定对象的原始值

 

 
二、filter()
array.filter(function(currentValue,index,arr), thisValue)   返回数组,包含了符合条件的所有元素。如果没有符合条件的元素则返回空数组。
参数: 
  currentValue 必须。当前元素的值
  index 可选。当前元素的索引值
  arr 可选。当前元素属于的数组对象
thisValue 可选。对象作为该执行回调时使用,传递给函数,用作 "this" 的值。
如果省略了 thisValue ,"this" 的值为 "undefined"
filter() 方法创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素。
注意: filter() 不会对空数组进行检测。
注意: filter() 不会改变原始数组。
 案例: done是 true 的
var array1 = [
      { "id": 0, "info": "dsfffffffffffhd", "done": false },
      { "id": 1, "info": "dsfffffffffffhd", "done": true },
      { "id": 22, "info": "dsfffffffffffhd", "done": false },
      { "id": 3, "info": "dsfffffffffffhd", "done": true },
      { "id": 42, "info": "dsfffffffffffhd", "done": false },
      { "id": 53, "info": "dsfffffffffffhd", "done": false },
      { "id": 6, "info": "dsfffffffffffhd", "done": true }
    ]

    var ar = array1.filter(function(value, index, arr) {
      return value.done === true
    })
    console.log(ar);
结果:

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
数组去重的方法