You can use filter() method to remove duplicates from array , if the index of the element gets matched with the indexOf value then only that element will get added.
let data = [1, 2, 3, 2, 1];
let uniqueData = data.filter((c, index) => {
return data.indexOf(c) == index;
});
console.log(uniqueData);
Output - [ 1, 2, 3 ]
Source : https://codelearningpoint.com/
Top comments (1)