Removing Duplicate Values From Arrary JavaScript And Other Array Functions

The best way of getting rid of duplicate values from the array is to use Array Object and new Set. The Array.from() function creates a new array instance from an array-like or iterable object. The Set object lets us store unique values of any type of iterable object, array, data. So, the simplest and the fastest way of getting unique value array is to use both the options.
  1. var duplicateArr = [1, 2, 3, 2, 3, 1, 3, 5, 4, 2, 1, 5, 8]    
  2. var uniqueArr = Array.from(new Set(duplicateArr));    
  3. console.log(uniqueArr); // output will be [1, 2, 3, 5, 4, 8]   
Note

This option will work only in ECMA Script 2015, 6th Edition and browser IE 11 and above.
 
FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support381213 11257.1
 
Ebook Download
View all
Learn
View all