JavaScript - Iterating over JSON object's properties

There are many situations where we have data in JSON format but you have to find the prop name yourself to retrieve the value of it. Here is a simple example to do it.

 

const data =
    {
        "19": [
            {
                "label": "tag 23",
                "value": 74
            }
        ],
        "29": [
            {
                "label": "tag 23",
                "value": 74
            }
        ]

    }


for (let dataKey in data) {
    let k= dataKey;
    let v= data[dataKey];
    console.log(dataKey,v);
}

 

Tags