remove duplicate value from map react js 1

remove duplicate value from map react js

var sandwiches = ['turkey', 'ham', 'turkey', 'tuna', 'pb&j', 'ham', 'turkey', 'tuna'];
var deduped = Array.from(new Set(sandwiches));

// Logs ["turkey", "ham", "tuna", "pb&j"]
console.log(deduped);

Here is what the above code is Doing:
1. We create a new Set object, which only allows unique values.
2. We pass the sandwiches array to the Set constructor, which removes any duplicate values.
3. We use the Array.from() method to convert the Set back into an array.

Similar Posts