I have two multidimensional arrays:
const parent = [['ff@gmail.com', 'a@a.com', 'f@f.com'], ['ff@gmail.com']];
const customers = [['hh@gmail.com'], ['gg@gmail.com']];
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:
[["hh@gmail.com", "ff@gmail.com", "a@a.com", "f@f.com"], ["gg@gmail.com", "ff@gmail.com", "a@a.com", "f@f.com"]]
what i would like to output is :
[["hh@gmail.com", "ff@gmail.com", "a@a.com", "f@f.com"], ["gg@gmail.com", "ff@gmail.com"]]
Any help would appreciate.