-1
I have the following object:
obj = {
"storySummaries": {
"featuredStories": [],
"trendingStories": [
{
"image": {
"newsUrl": "...",
"source": "...",
"imgUrl": "..."
},
"entityNames": [
"A",
"B",
"C"
]
}, {
"image": {
"newsUrl": "...",
"source": "...",
"imgUrl": "..."
},
"entityNames": [
"D",
"E",
"F"
]
}
]
},
"date": "4 de mar de 2019",
"hideAllImages": false
}
And I want to build an array with all fields of all entityNames.
How do I get an array of type ["A", "B", "C", "D", "E", "F"]
?
I tried the following code but found it very "ugly":
let hotTrendStories = JSON.parse(results)['storySummaries']['trendingStories'];
let entities = [];
hotTrendStories.forEach((story) => entities = entities.concat(story['entityNames']));
Simple and clear solution. I really liked this interpreter in the answer. Where can I learn more about it?
– Michael Pacheco
I can’t say, take a look at the meta, but I use with the
Ctrl + M
. Only one observation, the answer side has a , which serves to accept the answer that best met your question, but also has one that serves to score positively, the first you must choose only one answer to give, already the second can give to all– Costamilam