Answers for "how to remove duplicate data from array of object in react js"

4

how to remove duplicate array object in javascript

const arr = [{id: 1, name: 'one'}, {id: 2, name: 'two'}, {id: 1, name: 'one'}]

const ids = arr.map(o => o.id)
const filtered = arr.filter(({id}, index) => !ids.includes(id, index + 1))

console.log(filtered)
Posted by: Guest on October-12-2021
0

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);
Posted by: Guest on October-20-2021

Code answers related to "how to remove duplicate data from array of object in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language