Following, on《 Understand the Set structure in ES6 》In the article, we said that the new Set structure in ES6 is similar to an array, but there is no duplicate value. So we can use this feature to implement the array de duplication operation.
Use the Array.from method
First convert the array to Set type to remove duplicate values, and then use Array. from to convert it back to an array.
var arr = [1, 4, 3, 3, 2, 2, 3]; var newArr = Array.from(new Set(arr)); console.log(newArr); // [1, 4, 3, 2]
Use the extension operator... method
Similarly, first convert the array to Set type to remove duplicate values, then use the extension operator "..." to convert it to a comma separated parameter sequence, and finally put it into an empty array!
var arr = [1, 4, 3, 3, 2, 2, 3]; var newArr = [...new Set(arr)]; console.log(newArr); // [1, 4, 3, 2]