JavaScript · Junior · Question 48 of 75
How do you quickly remove duplicates from an array of primitives?
- ✓Correct answer:
[...new Set(arr)] - 2
arr.unique() - 3
Object.keys(arr)
Explanation
Set stores only unique values (SameValueZero comparison). Spread turns it back into an array. Arrays of objects need a key: for example, a Map by id.