No need for libraries or weird tricks
I believe it can save you some headache when dealing with removing duplicates from your array. Maybe you need to feed a library function with unique array values, or maybe something else.
How can you do that?
Old School Solution
With ECMAScript 5, you could so something like this
The native method
filter loops through our array, leaving only those entries that satisfy the function
uniqueValues . This function checks if a value is first occurring, if it is, then it’s not a duplicated value.
The ES6 shortened version of this might be something like
The New Way
Why overcomplicating our code? Why writing a function we don’t need after all. ES6 doesn’t force us to use the
filter method. Let’s use
Same result, fewer lines of code and more clarity. Often times the best solution is hiding behind the corner.
A note from the Plain English team
And as always, Plain English wants to help promote good content. If you have an article that you would like to submit to any of our publications, send an email to email@example.com with your Medium username and what you are interested in writing about and we will get back to you!