I have two arrays(arrayA & arrayB). I want to check if any of the items in arrayA allready exists in arrayB. if it doesn't I want to add it to arrayB(but that's not the problem). In the exampel I just want to console.log that I'm adding the item to array B.
First I thought this was a good idea:
for(var i = 0; i < arrayA.length; i++){
for (var j = 0; j < arrayB.length; j++) {
if(body[i].id == res[j].name){
console.log("The article allready exsists")
}
else{
console.log("Adding item to arrayB")
}
}
}
Then I realised that this wasn't a verry good way to do it because the array's are pretty big. Also the else-statement will be ran the number of times equal to the length of arrayA. Also It's a problem because the first time this will run the array length of arrayB will be zero and wont even reach the else-statement.
Is their any other ways to achive what I'm trying to do here?