I am trying to access the key and values of my nested array like this:
var obj = $.getJSON("mydata.json", function() {
console.log( "load success" );
});
Object.keys(obj[2].type).forEach(function(key) {
console.log(key, obj[key]);
});
But I get an error.
Here's the structure of the JSON file:
{
"nodes": [
{
"nd": "nd1",
"cat": "cat1"
}
],
"links": [
{
"id": 100
}
],
"types": [
{
"type": "one",
"image": "image001"
},
{
"type": "two",
"image": "image002"
},
{
"type": "three",
"image": "image003"
}
]
}
My goal is to get a list of values of:
one two three
var vals = obj.types.map((x) => x.image; });