ReactJs Remove Duplicates from Array
We can remove the duplicate values from an array in reactjs filter.
ReactJs Remove Duplicates from Array Example
You can use the simplest way to remove duplicate items from an Array simply as below-
Example:
var myArray = [100,80, 70, 80, 90,100, 71, 80]; const finalArray = []; const finalArray = myArray.filter(function(elem, pos) { return myArray.indexOf(elem) == pos; }); // will return [100, 80, 70, 90, 71]; |
On the same way we can remove any duplicate value from array.
Output of above example will be array of unique values- [100, 80, 70, 90, 71];
Advertisements