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 a unique value array is to use both the options.
- var duplicateArr = [1, 2, 3, 2, 3, 1, 3, 5, 4, 2, 1, 5, 8]
- var uniqueArr = Array.from(new Set(duplicateArr));
- 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.
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
| Basic support | 38 | 12 | 13 | 11 | 25 | 7.1 |

Join the conversation! Your thoughts help the community grow.