Answers for "remove object from array by repeated value"

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

how to remove duplicate values in array of objects using javascript

const array = [{id: 1, name: "hello"}, {id: 2, name: "hii"}, {id: 1, name: "hey"} ]; 
const cleanArray = array.reduce((unique, o) => {
        if(!unique.some(obj => obj.id === o.id)) {
          unique.push(o);
        } 
        return unique;
    },[]);
Posted by: Guest on March-14-2022

Code answers related to "remove object from array by repeated value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language