<>ES6 Three simple methods of array de duplication

<> Let's talk about the use of ES6 Three ways to realize array de duplication .
<> The first kind : utilize Map Object and array filter method
Paste the relevant code

Printed results

By printing, we found that , It really achieved the effect we wanted . So here's a brief explanation .

1.Map The target is ES6 Provides a new data structure , among has The way to do this is to return a Boolean value , Indicates whether a value has a current value Mp Among the objects ,set The best way is to give Map Object settings key/value.
2.filter() Method to create a new array , The elements in the new array are checked by all the elements in the specified array that meet the criteria .
So ,Map Object combination filter Method can achieve the effect of array de duplication ~
<> The second kind : utilize Set Object and array Array.from method
Also paste the relevant code fragment

Print the running results

In a nutshell , The second method is simpler than the first . Let's also explain briefly .
1.Set yes ES6 New data structure , It's like an array , But there are no duplicate values .
2.Array.from Method is used to turn two types of objects into real arrays : Array like objects (array-like object) And ergodic (iterable) Object of ( include
ES6 New data structure Set and Map).

therefore set combination Array.from It can also achieve the effect of array de duplication . But it should be noted that , Mainstream browsers like Chrome,Firfox,Opera,Safari, Including Microsoft's Edge, They are all supportive , But only IE Series not supported .

<> The third kind : utilize Set+ Extension operator …

The third way is simpler
Paste the relevant code

Results run after printing

<> That's how to use it ES6 Three ways to achieve array de duplication with new features , The common advantage of these three methods is that the code is concise , about undefined and NaN It can also achieve the effect of weight removal ~~

<> If you have other ways, please share them ~

©2020 ioDraw All rights reserved
Using genetic algorithm to solve function optimization problem ( Single target )CLion Novice step on the pit :CMake project is not loaded Google says home office affects work efficiency !2021 Return to offline office in 2010 Data analysis interview experience ( Give yourself a process of carding )C Language implementation of simple minesweeping ( It's all dry goods , Novice Xiaobai must see )Python Basic knowledge !!C Language implementation of minesweeping game Valentine's Day , rose , The one in your heart ~ Operation and maintenance work Python Painting cherry blossoms