I have this array which is eewootags
:
and I have another array evProductTag
which is below:
I am trying to get the id which is common to both.
This is what I tried:
var tagdataexist = [];
for (var i = 0; i < evProductTag.length; i++) {
for (var j = 0; j < eewootags.length; j++) {
if (eewootags[j].name == evProductTag[i].name){
tagdataexist.push(eewootags[i].id);
}
}
}
console.log(tagdataexist);
But this gives be 193
instead of 187
.
Tag2
is the common element by name.
Please help!
question from:https://stackoverflow.com/questions/66054419/javascript-get-common-element-in-two-arrays