Reputation: 304
I have array, which contains arrays of objects from different tables. How can I get all names of all these objects in array of arrays? I know, they are weirdly nested, but that's how structure is for now.
Upvotes: 1
Views: 1275
Reputation: 851
use a nested for loop on the array
var names = []
for (let i = 0 ; i < array.length ; i++){
for(let j = 0 ; j<array[i].length; j ++){
names.push(array[i][j].name)
}
}
console.log(names)
Upvotes: 0
Reputation: 6257
Just write:
const getNames = (data) => data.flat().map(({name})=> name)
Upvotes: 1