crazylane
crazylane

Reputation: 62

Get value from array of objects in jQuery

I have the following JSON which I keep in strConfig variable:

{
    "import": [
        {
            "drive": "F",
            "path": "F:\\\\PageExports\\\\",
            "pagestatus": "1",
            "withnextpages": "1"
        }
    ],
    "export": [
        {
            "drive": "F",
            "path": "F:\\\\PageExports\\\\",
            "followmainlink": "0"
        }
    ]
}

I transorm it to an object by:

var objConfig = jQuery.parseJSON( strConfig );

Could you tell me how do I get one of values from that object and assign it to a variable, please (let's say value of import.pagestatus)? I tried:

console.log($(objConfig).find('export').find('pagestatus').value);

but that gives me 'undefined' in console. Any help will be appreciated.

Upvotes: 0

Views: 49

Answers (2)

Harpartap Singh Permar
Harpartap Singh Permar

Reputation: 289

Use this:

var resp = jQuery.parseJSON(resp);
var drive =  resp.import.drive;
alert(drive);

Upvotes: 0

Nishit Maheta
Nishit Maheta

Reputation: 6031

use below code

 objConfig.import[0].pagestatus

it will give value of pagestatus inside import

Upvotes: 2

Related Questions