Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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;
    },[]);
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #remove #duplicate #values #array #objects #javascript
ADD COMMENT
Topic
Name
7+4 =