DEV Community

Discussion on: Remove Duplicates In Array

Collapse
 
juliandierkes profile image
Julian Dierkes

Cool haven't thought of using "Set" yet. You could also filter directly on the array:

const unique = myArr.filter((value, index, array) => array.indexOf(value) === index);

Collapse
 
miketalbot profile image
Mike Talbot ⭐

That is significantly slower though, the Set uses an O(1) lookup so the routine is O(N) whereas indexOf would make it O(N**2)

Collapse
 
juliandierkes profile image
Julian Dierkes

Nice to know. Will try that next time.