MJ
asked on
How to access jason value with javascript
If I have something like this in my javascript:
var newArray = [
{ "name": "Dagny Taggart", "age": 39 },
{ "name": "Francisco D'Anconia", "age": 40 },
{ "name": "Hank Rearden", "age": 46 }
]
What is the best way to access the data based on the name and grab the age? I understand I could loop through with and match
newArray[i].name
and grab
newArray[i].age
but is there another way that is easier? Is there a way to pass in a key and do something like
newArray['Dagny Taggart']
and access the data? I've never used JSON before.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window