Arrays in JavaScript can contain the same value several times. Going through Set
, we can filter them down to unique values.
const unique = array => [...new Set(array)]
// each value in this array is also how many of it are in there
unique([1, 2, 3, 3, 4, 4, 3, 4, 2, 4]) // ⇒ [1, 2, 3, 4]
For more tips like this, check out the full collection on my website: islovely.co/firetips
Top comments (0)