Its quite a simple problem but I am unable to figure out the logic.
I have Arr1 = [1,2,3,4] and Arr2 = [3,4,5,6]
I would like compare Arr2 with Arr1 and add missing values to
MissingArr = [];
my code
let missing = [];
arrOfNum.forEach( (number) => {
// Arr2 = 3,4,5,6
console.log("number: "+number);
for(let i = 0; i < this.numbers.length; i++){
// Arr1 = 1,2,3,4
console.log("this.numbers: "+this.numbers[i]['number']);
if(number == this.numbers[i]['number'])
{
//Do Nothing
}else{
missing.push(this.numbers[i]['number']);
}
}
});
I am not sure how to do a check of Arr2 to Arr1 (complete entire forloop) and only if Arr2 value does not exist in Arr1 then add it to missing array.
Update
Arr1 = [{id:1, number:1}, {id:2, number:2},{id:3, number:3}, {id:4, number:4}]
Arr2 = [3,4,5,6]
so missing array should be: Missing= [5,6]
Arr2.filter(e => !Arr1.includes(e));?