Skip to content Skip to sidebar Skip to footer

Access Array In Array In Javascript

I am getting a JSON reply, like following: [{ 'order_id': '12', 'customer': 'user user', 'status': 'Pending', 'date_added': '02\/09\/2012', 'total': '$500.00', 'action'

Solution 1:

Like you said, action is an array. Thus, you can't access it using data[i]['action']['href']. You have to use a subscript to indicate the position of the array that you want. For example, to access the first position, you'd use:

var href = data[i].action[0].href;
var text = data[i].action[0].text;

Solution 2:

action is an array containing an object with a property called text. Change:

data[i]['action']['text']

to:

data[i]['action'][0]['text']

Post a Comment for "Access Array In Array In Javascript"