Need to push the array object(arr1) valeus into another array object(arr2) if the value not exist. The existing values will not push into another array.
var arr1 = [{
name: 'fred'
}, {
name: 'bill'
}, {
name: 'ted'
}, {
name: 'james'
}];
var arr2 = [{
name: 'spil'
}, {
name: 'fred'
}, {
name: 'bill'
},{
name: 'paul'
}, {
name: 'stone'
}];
function add(name) {
var found = arr1.some(function (el) {
return el.name === name;
});
if (!found) {
arr1.push(arr2);
}
return arr2;
}
adddo?arr2, but your code does the opposite (or sort of tries to). Given that youradd()function seems to take a string as input, what should happen (a) if the value is currently in neither array? (b) If it is currently in onlyarr1? (c) If it is currently in onlyarr2? (d) If it is already in both arrays?