Simplest ‘removeDuplicates’ in JavaScript Arrays
Other question I’ve found a lot in job interview questions, and this is the simplest implementation I’ve found:
[…].filter(function (val, idx, arr) {
var firstIdx = arr.indexOf(val);
return (idx === firstIdx) || (firstIdx === arr.lastIndexOf(val));
});
Written by Gonçalo Morais
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Array
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#