//array de-weight{Const ARR= [1,2,3,4,1,23,5,2,3,5,6,7,8,undefined,NULL,NULL, Undefined,true,false,true, ' Chinese ', ' ', ' ', ' hello ', ' Chinese ']; //First KindConst R = [...NewSet (arr)]; Console.log (R); //[1, 2, 3, 4, 23°c, 5, 6, 7, 8, undefined, NULL, True, False, "Chinese", "", "Hello"] //The second KindConst R = Arr.reduce ((all,name) = All.includes (name)?All : [... all,name],[]); Console.log (R); //[1, 2, 3, 4, 23°c, 5, 6, 7, 8, undefined, NULL, True, False, "Chinese", "", "Hello"] //Third KindConst K = Arr.filter (item, i) = = = = = =Arr.indexof (item)); Console.log (k); //[1, 2, 3, 4, 23°c, 5, 6, 7, 8, undefined, NULL, True, False, "Chinese", "", "Hello"]}//Count the number of occurrences of each element in the array{Const ARR= [' Zhangsan ', ' Lisi ', ' Wangwu ', ' Zhangsan ', ' Lisi ', ' Wangwu ', ' Zhaosi ', ' Liuneng ']; Const R= Arr.reduce ((all, name) = ={ if(NameinchAll ) {All[name]++ }Else{All[name]= 1; } returnAll ; },{});Console.log (R);//{Zhangsan:2, Lisi:2, Wangwu:2, Zhaosi:1, liuneng:1}}//Array Object de-weight{Const ARR=[{name:' Zhangsan ', Age:12}, {name:' Lisi ', Age:14}, {name:' Zhangsan ', Age:12}, {name:' Lisi ', Age:14}, {name:' Zhangsan ', Age:12}, {name:' Lisi ', Age:14}, {name:' Zhangsan ', Age:12}, {name:' Wangwu ', Age:16}, {name:' Wagnwu ', Age:16}, {name:' Lisi ', Age:14 }, ] //according to age to go heavy //Method OneConst AGE = ' age '; Const R= Arr.reduce (all, next) = All.some (Atom) = atom[age] = = Next[age])?All : [... all, next],[]); Console.log (R);}
Es array de-weight, the objects inside the array go heavy