I have a JSON file, I need to get all urn elements;

[ { "name": "One", "children": [{ "urn": "urnOne" }, { "name": "ChildrenOne", } ] }, { "name": "Two", "children": [{ "urn": "urnTwo" }, { "name": "ChildrenTwo", } ] } ] 

My code can't do this.

 fetch('./viewables.json') .then(response => ./json.json()) .then(data => { data.forEach((el, i) => { data[i].children.urn; }) }); 

    1 answer 1

    children are not represented here as an object, but as an array, so you need to specify which ordinal element to refer to (in this case, [0])

     fetch('./viewables.json') .then(response => ./json.json()) .then(data => { data.forEach((el, i) => { data[i].children[0].urn; }) }); 
    • Thank you bro, what you need! - Alisa Bondarchuk