I have two multidimensional arrays:
const parent = [['[email protected]', '[email protected]', '[email protected]'], ['[email protected]']];
const customers = [['[email protected]'], ['[email protected]']];
I would like to compare the parent[0] with customers[0] and parent[1] to customers[1] and if the customers is not contain the parent element push it to customer.
what i try:
for(let x= 0; x < parent.length; x++){
const innerArray = parent[x].length
for(let y = 0; y < innerArray; y++){
for (const customer of customers){
if (!customer.includes(parent[x][y])){
customer.push(parent[x][y])
}
}
}
}
console.log(customers)
the above code output is:
[["[email protected]", "[email protected]", "[email protected]", "[email protected]"], ["[email protected]", "[email protected]", "[email protected]", "[email protected]"]]
what i would like to output is :
[["[email protected]", "[email protected]", "[email protected]", "[email protected]"], ["[email protected]", "[email protected]"]]
Any help would appreciate.