My goal is to extract a specific field value from a nested array within an object array. Using the map method, I attempted to achieve this but ended up with two empty arrays nested inside two empty objects. Though I am aware of this mistake, it indicates the direction of my thought process.
function getChildArray(item, index) {
var x = [item.hobbies]
return x
}
console.log(parentArray.map(getChildArray))
Here is a glimpse of my document structure:
[
{
"id":12345678900,
"name":"Jasmin",
"age":27,
"hobbies":[
{
"id":1221,
"name":"hiking",
"when":"anytime"
},
{
"id":9865,
"name":"eating",
"when":"all the time"
}
]
},
{
"id":223456789001,
"name":"Joe",
"age":35,
"hobbies":[
{
"id":989,
"name":"gaming",
"when":"anytime"
},
{
"id":2355,
"name":"online gaming",
"when":"all the time"
}
]
}
]
I am interested in knowing how I could retrieve a list of Joe's hobbies by name only.