Remove the duplicate values from two arrays using JavaScript:
var array1 = [{id:1,name:'Raju',status:'0.Initial'},{id:2,name:'Santosh',status:'1.Capital'}]
var idsToRemove = [];
array1.forEach(function(dt){
idsToRemove.push(dt.id)
});
var array2 = [{id:1,name:'Raju',status:'0.Initial'},{id:2,name:'Santosh',status:'1.Capital'},{id:3,name:'Jhon',status:'2.Foundation'}]
var leftData = [];
array2.forEach(function(dt){
if(idsToRemove.indexOf(dt.id) == -1){
leftData.push(dt);
}
});
console.log(leftData);
Output:
Hey user,
Thank you for studying the blog
Please comment if any error/ suggestions found for above data.
Comments
Post a Comment