See the notes recorded before, originally to heavy so many methods, ha ha ha

/** * 2020-10-23@param {var arr =,1,1,2,3,4,5,6,7 [1]}* /
1 / / method
var newarr = [...new Set(arr)];

2 / / method
var newarr = arr.filter((ele, index, array) = > {
  return index === array.indexOf(ele);
});

/ / 3
Array.prototype.newarr = function () {
  var newarray = [];
  var len = this.length;
  for (var i = 0; i < len; i++) {
    var cur = this[i];
    if (newarray.indexOf(cur) === -1) { newarr[newarr.lenth] = cur; }}return newarr;
};

// The following implementation method theme idea is: double loop deweight
// If the first occurrence of the ith element in the current array is I, the array will be saved. Otherwise, it is repeated
function uniq(arr) {
  var temp = [];
  for (var i = 0; i < arr.length; i++) {
    if(arr.indexOf(arr[i] === i)) { temp.push(arr[i]); }}return temp;
}

5 / / method
var obj = {};
var arr1 = [];
for (var i = 0; i < arr.length; i++) {
  var cur = arr[i];
  if(! obj[cur]) { obj[cur] =true;
    arr1.push(cur);
  }
}
obj = null; // Release obj after operation

// Indxof is the simplest kind
var arr1 = [];
for (var i = 0; i < arr.lenth; i++) {
  var cur = arr[i];
  if (arr1.indexOf(cur) === -1) { arr1.push(cur); }}// method 7 map de-weight
// the map() MDN:map() method creates a new array. The result is that each element in the array is the return value of a one-time call to the provider function
// New Map(): The Map structure provides value-value correspondence, which is a more complete implementation of hash structures. If you need a key-value pair data structure, map is better than Object.
// It is a collection of key-value pairs similar to objects,
// However, the scope of 'key' is not limited to strings. All types of values (including objects) can be used as keys
// If the map's key is a value of a simple type (number, string, Boolean), as long as the two values are strictly equal, the map will treat it as a key, including 0 and -0.
// Also, although NAN is not strictly equal to itself, Map treats it as a key
//@param {var map=new Map() map.set(['a'],555) map.get('a') //undefined }
Methods: / / instantiate the attributes set, get, the size, has, delete, clear
// Traverse methods: keys(),values(),entries(),forEach()
// When it comes to data structures, map can be used, but array cannot be used, especially for complex data structures.
// If the array is unique, use set, and map is preferred. If the array is unique, use map.
// Use set instead of array
const map = new Map(a); arr.filter((item) = >! map.has(item) && map.set(item,1));

// Use reduce to reduce weight
The MDN: reduce() method performs a self-defined reducer function (executed in ascending order) on each element in the array and summarizes its results into a single return value
// Provide 4 parameters, acc(accumulator), CUR (current value), IDX (current index), SRC (source array)
arr
  .reduce(function (accumulator, currentValue) {
    if (accumulator.indexOf(currentValue) === -1) {
      accumulator.push(currentValue);
    }
    returnaccumulator; } []) [// Convert a two-dimensional array to a one-dimensional array
    ([1.2], [3.4], [5.6.7])
  ].reduce((acc, cur) = > {
    acc.concat(cur);
  });
Copy the code