1, using ES6 new feature, Set structure is removed, return the Set structure type data, then use the [extension operator] or [array.from ()] method to convert the real Array structure

/ / 【 method 】 es6 Set structure let arr = [" 2 ", "3", "5", "2", "eight", "7", "0", "3", "5"); let set = new Set(arr); /* An array of classes (set) can be converted to a real array: 1, [...set]; 2, Array. The from (set); */ let result = [...set]; / / / "2", "3", "5", "eight", "7", "0"] / * or * / let result_1 = Array. The from (set); // ["2", "3", "5", "8", "7", "0"]Copy the code

2. Use the indexOf() method to check whether an element exists in an array. If so, returns the index of the element in the array. Otherwise -1 is returned;

/ / an array of method 2 】 【 indexOf () method to let arr = [" 2 ", "3", "5", "2", "eight", "7", "0", "3", "5"); let newArr = []; for (let i = 0; i < arr.length; I ++) {if (newarr.indexof (arr[I]) === -1) {// arr[I] does not exist in newarr.push (arr[I]); } } console.log(newArr); // ["2", "3", "5", "8", "7", "0"]Copy the code

3. The original array uses the indexOf() method to retrieve the location of the element’s first occurrence

/ / 【 methods 】 the array subscript method let arr = [" 2 ", "3", "5", "2", "eight", "7", "0", "3", "5"); let newArr = []; for (let i = 0; i < arr.length; I ++) {if (arr.indexof (arr[I]) === I) {// Newarr.push (arr[I]); } } console.log(newArr); // ["2", "3", "5", "8", "7", "0"]Copy the code

4. Sort the array using the sort() method, and then compare the previous values with the latter values, and put the different values into the new array

/ / array method four 】 【 sort () method to let arr = [" 2 ", "3", "5", "2", "eight", "7", "0", "3", "5"); // Sort the array by adding the first element to the new array arr.sort(); let newArr = [arr[0]]; for (let i = 1; i < arr.length; i++) { if(arr[i]! ==newArr[newarr.length-1]){// The last element in the arR array is different from the previous element newarr.push (arr[I])}} console.log(newArr); // ["0", "2", "3", "5", "7", "8"]Copy the code