Verify whether the second array includes the elements from the first array and display them, otherwise show the elements from the second array that are not in the first one.
var contacts = [{name:'muzz',no:1},{name:'muzamil',no:2},{name:'hamza',no:3}]
var recipient = ['2','4']
function check () {
contacts.forEach(({name,no}) => {
if(recipient.includes(no.toString())){
console.log('exists',name)
}
else {
recipient.forEach(e =>{
if(!recipient.includes(no.toString()) && contacts == no){
console.log(e);
}
})
}
})
}
Please point out any errors in my code. The 'else' block seems to be iterating through all elements again unnecessarily.