I'm attempting to extract the type
and url
values from the media2
object within this JSON array and assign them to an AngularJS scope Array.
"results":[
{
"session2":[
{
"__type":"Object",
"about":"about here",
"attendant2":{
"__type":"Relation",
"className":"_User"
},
"className":"sessionClass",
"createdAt":"2015-09-16T06:12:54.461Z",
"media2":[
{
"__type":"Object",
"priority":1,
"type":3,
"updatedAt":"2015-09-16T06:12:54.153Z",
"url":"https://example.com"
}
],
"updatedAt":"2015-09-16T06:12:54.461Z"
}
],
"updatedAt":"2015-10-16T06:08:57.726Z"
}
]
I have tried using the following code snippets:
$scope.mediaType = results['object'].map(function(item) {
return item.get('session2')[0].get('media2')[0].get('type');
});
and this
$scope.mediaType = results['session2'].map(function(item) {
return item.get('media2')[0].get('type');
});
However, I keep receiving
TypeError: results.object is undefined
or TypeError: results.session2 is undefined
. How can I access the value from that JSON?