I have an array which contains arrays of objects. Here is an example:
[ [{name: Alex, number: 2}, {name: Bill, number: 3}], [{name: John, number: 5}, {name: Aston, number: 7}]]
I want to create another array which contains all the objects of the above array of arrays like this:
[{name: Alex, number: 2}, {name: Bill, number: 3}, {name: John, number: 5}, {name: Aston, number: 7}]
I wrote the code below:
const productsInfoArray = [];
const productsRecords = customerContacts.map(i => i.products).map(product => {
product.map(i => productsInfoArray.push(i));
return productsInfoArray;
});
But when I console.log(productsRecords)
an array of array is being returned which contains all the info. The problem is that this array contains the 12 times the wanted array because customerContacts length is 12