Reputation: 1
I'm a Node.js newbie trying to parse the following JSON:
var data1 = {
"_id":"R1::table::A1::order::167::comanda::2",
"_rev":"1-ed6df32d3b4df9cc8019e38d655a86f5",
"comanda":[
[
{
"category":"Entradas",
"itemName":"Ensalada de betabel",
"modifierList":[
{
"modifierGroupName":"Modificadores de ensalada",
"modifierName":"Aderezo ranch",
"modifierPrice":10
},
{
"modifierGroupName":"Tamaños de Ensalada de betabel",
"modifierName":"Ensalada de betabel Grande",
"modifierPrice":100
}
],
"modifiersTotal":110,
"price":0
}
]
],
"docType":"comanda",
"operation":"N",
"restaurantId":1,
"userId":"admin"
}
and I would like to get the values from "itemName"
within "comanda"
array and "modifierName"
within "modifierList"
array for further processing.
In order to get "itemName"
I tried the following:
console.log('itemName:' + data1.comanda[0].itemName);
But I got this as result:
itemName: undefined
Any ideas on how to get these inner values? Thanks a lot!
Upvotes: 0
Views: 2360
Reputation: 1769
You have two nested arrays there so it should be like this:
data1.comanda[0][0].itemName
The same for modifierName
.
Upvotes: 1