I have little problem with Js arrays. I have two arrays - one is correct all the time (created with correct data) and one is coming from fetching basically. I'm trying to compare these two arrays and I'm able to get their matching items, but not the items that aren't matching:
var results = [];
var controlArray = ['T', 'M', 'P', 'N']
var fetchArray = ['T', 'M', 'PP', 'N ']
for (var i = 0; i < controlArray.length; i++) {
for (var j = 0; j < fetchArray.length; j++) {
if (controlArray[i] === fetchArray[j]) {
results.push(fetchArray[i]);
}
}
}
Output should be like:
results = ['PP', 'N '];
or:
results = ['P', 'N'];
So it would indicate where the problem is. Both of these woukd work.
This gives me matching part. I have tried to put just !== but in that case it throws out basically everything multiple times and I can't see logic why shouldn't it work like that. Also the white space is important.
Any ideas to painlessly get the not matching values out of these arrays?