how to remove duplicate array object in javascript
let person =[{name:"john"},{name:"jane"},{name:"imelda"},{name:"john"},{name:"jane"}];const data =Array.from(newSet(person.map(JSON.stringify))).map(JSON.parse);console.log(data);
how to remove duplicate array object in javascript
let person =[{name:"john"},{name:"jane"},{name:"imelda"},{name:"john"},{name:"jane"}];const obj =[...newMap(person.map(item=>[JSON.stringify(item), item])).values()];console.log(obj);
how to remove duplicate array object in javascript
var arrayWithDuplicates =[{"type":"LICENSE","licenseNum":"12345",state:"NV"},{"type":"LICENSE","licenseNum":"A7846",state:"CA"},{"type":"LICENSE","licenseNum":"12345",state:"OR"},{"type":"LICENSE","licenseNum":"10849",state:"CA"},{"type":"LICENSE","licenseNum":"B7037",state:"WA"},{"type":"LICENSE","licenseNum":"12345",state:"NM"}];functionremoveDuplicates(originalArray, prop){var newArray =[];var lookupObject ={};for(var i in originalArray){
lookupObject[originalArray[i][prop]]= originalArray[i];}for(i in lookupObject){
newArray.push(lookupObject[i]);}return newArray;}var uniqueArray =removeDuplicates(arrayWithDuplicates,"licenseNum");console.log("uniqueArray is: "+JSON.stringify(uniqueArray));
combine 2 "arrays with objects" and remove object duplicates javascript
// Join Without Dupes.constjoinWithoutDupes=(A,B)=>{const a =newSet(A.map(x=> x.item))const b =newSet(B.map(x=> x.item))return[...A.filter(x=>!b.has(x.item)),...B.filter(x=>!a.has(x.item))]}// Proof.const output =joinWithoutDupes([{item:"apple",description:"lorem"},{item:"peach",description:"impsum"}],[{item:"apple",description:"dolor"},{item:"grape",description:"enum"}])console.log(output)