DEV Community

Discussion on: Basic Javascript: Removing Duplicates from an Array

mschleeweiss profile image
Marc Schleeweiß • Edited on

The only code snippet that works is the first one. All others throw some kind of error or have side effects.

  1. forEach throws Uncaught SyntaxError: Unexpected token [ because of the weird function declaration.

  2. map throws Uncaught SyntaxError: Unexpected token new. Why would anyone name a variable new?

  3. Set does work, but modifies the original array. Nick Taylors solution [ Set(array)] does the same but better.

I am not sure where you got these but I would suggest taking some time to at least test the snippets next time you do a blog post.

antonioavelar profile image
António Avelar

that variable definition simply blows my mind... (let new;)

rudoslav profile image

I was surprised that the author and others commenting did not actually realize this :)

But I guess it does not dissolve the point of the post.