I'm parsing a JSON which does not start with [] brackets. Instead you see the following:
{
"result":{
"heroes":[
{
"name":"npc_dota_hero_antimage",
"id":1,
"localized_name":"Anti-Mage"
},
...
]
}
}
There are a total of 115 items.
When trying to use ES6's spread operator ...
like so,
const endpoint = './heroes.json'
let heroes = []
fetch(endpoint)
.then(blob => blob.json())
.then(data => heroes.push(...data))
I will not be able to iterate over the JSON due to result
and heroes
shielding the objects.
Is there a way to use the spread operator on the above JSON structure?
If so, how then would i console log to give me the first item's name of Anti-Mage
?