Newcoma
Newcoma

Reputation: 809

json iteration in jquery

I have this json

{
    "3": {
        "builderName": "All Branches",
        "currentStep": {
            "eta": 46.228333592710214,
            "expectations": [
                [
                    "output",
                    1519065,
                    1565397.0
                ]
            ],

I want to get keys and values from currentStep. Like eta and expectations.

$.each(obj, function (key, value) {
    $.each(value.currentStep, function (key, value) {
       console.log(value.eta); // this returns undefined            
    });
});

Upvotes: 0

Views: 46

Answers (2)

Danny
Danny

Reputation: 7518

You already have the key and value.

$.each(json, function (key, value) {
    $.each(value.currentStep, function (key, value) {
       console.log(key + " : " + value);            
    });
});

JSFiddle

Upvotes: 2

ThiefMaster
ThiefMaster

Reputation: 318488

This will log the keys/values of currentStep:

$.each(obj, function(key, value) {
    $.each(value.currentStep, function(key, value) {
        console.log(key, value);
    });
});

Upvotes: 1

Related Questions