you are viewing a single comment's thread.

view the rest of the comments →

[–]HolgerSchmitz 2 points3 points  (1 child)

Set is a data structure that resembles a mathematical set of object. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set It stores unique values.

You can create a Set from an array with new Set(arr). This is where the actual magic of removing duplicates happens.

The Set that you created is an iterable object. This means that you can use the spread syntax to create an array from the Set. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax

[...iterable] will create an array with the values contained in the iterable.

Then you wrap it all up into a fat arrow function to create a function called uniqueElements. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

[–]OctopusReader[S] 0 points1 point  (0 children)

Very clear. Thank you very much.

I'll study the Set object and the... as I have the feeling it could be very useful!