DEV Community

Discussion on: Removing duplicate elements in Javascript: In a simple way! 😵

Collapse
codewithnithin profile image
codeWithNithin

nice.
for higher order function lovers , we can do the same thing by

const nums = [1, 2, 2, 3, 1, 2, 4, 5, 5, 6, 4, 2, 6];
nums.filter((v,i) => nums.indexOf(v) == i  );
Enter fullscreen mode Exit fullscreen mode
Collapse
ngnam profile image
NamNguyen

numsObject = [{id: 1, name: 'one', {id: 2, name: 'two'}] ?

Collapse
henryjw profile image
Henry Williams • Edited on

Like @lukeshiru said, this works but is much slower. O(n^2) vs O(n). It's fine for small arrays, but would be slow as the array gets bigger.

Collapse
lukeshiru profile image
LUKESHIRU

Yup, only thing to consider is that it's slower.