Lets look at it line by line.
var entries = [1, 2, 2, 3, 4, 5, 6, 6, 7, 7, 8, 4, 2, 1]
This creates an array entries
with some list of numbers.
Now when we do, new Set(entries)
, we create a Set
from entries
array.
A Set
is a collection of distinct elements as you may already know.
Hence, new Set(entries)
gives us a Set
from entries
as follows:
Set(8) {1, 2, 3, 4, 5, …}
Now, ...
operator spreads the distinct elements from the Set
to create an array, which is the line - var unique_entries = [...new Set(entries)]