mardi 3 février 2015

Accessing a JSON attribute that is equal to a specific value in javascript [duplicate]



This question already has an answer here:




I have a JSON object array like this:



people {
{
name: 'Alice',
age: '25',
},
{
name: 'Bob',
age: '34'
}
}


I want to access the 'age' value of an person which has an 'name' value of 'Alice'. How do I do this in javascript? Something like (in pseudocode of what the logic is I'm aware this is not possible in javascript):



people['age'].value where name == 'Alice'


and the result would be: '25'. There seem to be a lot of related JSON questions, but none of the ones I found (as far as I could find) addressed this particular question





Aucun commentaire:

Enregistrer un commentaire