Removing Duplicate Elements from Arrays
Problem
You want to remove duplicate elements from an array.
Solution
Discussion
There are many implementations of the unique
method in JavaScript. This one is based on “The fastest method to find unique items in array” found here.
Note: Although it’s quite common in languages like Ruby, extending native objects is often considered bad practice in JavaScript (see: Maintainable JavaScript: Don’t modify objects you don’t own; Extending built-in native objects. Evil or not?).