include() methods. Yet using
Set with a combination of
spread operator is the simplest approach.
Set is an iterable object which lets you store unique values of any type, whether primitive values or object references. We use the spread syntax (
...) to convert the
Set object to an array.
1const arr = [1, 2, 3, 5, 3, 8, 13, 13, 21, 5, 3, 2, 21];23console.log([...new Set(arr)]);4// Output: [1, 2, 3, 5, 8, 13, 21]
Sign up to get updates when I write something new. No spam ever.Subscribe to my Newsletter