I need extract data (array.tags.name) from all fields and put them to result array.
3
Just loop through with nested loop.
const result = []; for (const item of array) { const tags = item.tags; for (const tag of tags) { result.push(tag.name); } } console.log(result);
Here the code to get arrays.tags.name. I have tested this with your given data as well.
const data = [ { tags: [ { name: 'LandingPage', value: 'true' }, { name: 'Country', value: 'GB' }, { name: 'Carrier', value: 'Evri' }, { name: 'EventCode', value: 'Dispatched' } ] }, ]; const results = []; for (let column of data) { for (let tag of column.tags) { results.push(tag.name); } } console.log(results);
Solution using map.
map
const data = [ { tags: [ { name: 'LandingPage', value: 'true' }, { name: 'Country', value: 'GB' }, { name: 'Carrier', value: 'Evri' }, { name: 'EventCode', value: 'Dispatched' } ] } ]; const results = data.map(item => item.tags.map(tag => tag.name)).flat(); console.log(results);
Click here to cancel reply.
3
Answers
Just loop through with nested loop.
Here the code to get arrays.tags.name. I have tested this with your given data as well.
Solution using
map
.