0

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!

1 Answer 1

1

You have two nested arrays there so it should be like this:

data1.comanda[0][0].itemName

The same for modifierName.

Sign up to request clarification or add additional context in comments.

1 Comment

@javsonic Please always accept answers if you think they are good - so the question does not appear in 'Unanswered' section. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.