0
var resobj = {
    "status": {
        "code": 2000,
        "message": "Success"
    },
    "order": {
        "Shop": 1,
        "Quantity": 1,
        "Customer": 1 
    }
}

I have this json and I need to loop through the order and access the keys(shop,quantity,customer).Can anyone help me on this.

Süresh AK
  • 344
  • 3
  • 20

2 Answers2

0

Using Object#keys will return you the array of keys

var resobj = {
    "status": {
        "code": 2000,
        "message": "Success"
    },
    "order": {
        "Shop": 1,
        "Quantity": 1,
        "Customer": 1 
    }
};

Object.keys(resobj.order).forEach(key => console.log(key));
Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112
0

What you're looking for is Object.keys [MDN]

Example:

Object.keys(resobj.order).forEach((key) => {
    console.log(key);
});
// Will log the keys "Shop", "Quantity" and "Customer"
floriangosse
  • 1,124
  • 1
  • 8
  • 19