For the following tree
var items = {
'drinks': [
{
'name': 'coke',
'sugar': '1000'
},
{
'name': 'pepsi',
'sugar': '900'
}
]
};
Is there a way to do something like
function get_values(data) {
var items = JSON.parse(items)
return items.data[0].name;
}
get_values('drinks');