Your problem is with the indexes of your array: you access eewootags
with both i
and j
. You need to use always the same index!
let eewootags = [
{id: 193, name: 'Tag 8'},
{id: 186, name: 'Tag1'},
{id: 187, name: 'Tag2'},
{id: 188, name: 'Tag3'},
{id: 189, name: 'Tag4'},
{id: 190, name: 'Tag5'},
{id: 191, name: 'Tag6'},
{id: 192, name: 'Tag7'},
{id: 194, name: 'Tag9'}
];
let evProductTag = [
{name: 'Tag2'},
{name: 'Tag 3'},
{name: 'Tag 69'}
];
let tagdataexist = [];
for (let i = 0; i < eewootags.length; i++) {
for (let j = 0; j < evProductTag.length; j++) {
if (eewootags[i].name == evProductTag[j].name) {
tagdataexist.push(eewootags[i].id);
}
}
}
console.log(tagdataexist);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…