Assume that i have this json obj:
var person=[{"name":"joe","age":21,"class":"a"},{"name":"moe","age":22,"class":"b"}];
i want to get the age of joe using given name which is joe.
is there something like this:
var age = person.name['joe'].age
Assume that i have this json obj:
var person=[{"name":"joe","age":21,"class":"a"},{"name":"moe","age":22,"class":"b"}];
i want to get the age of joe using given name which is joe.
is there something like this:
var age = person.name['joe'].age
You can use Array.prototype.find to search for a specific property in an array of objects.
var person=[{"name":"joe","age":21,"class":"a"},{"name":"moe","age":22,"class":"b"}];
const joe = person.find(item => item.name === 'joe');
if(joe)
console.log(`Joe is ${joe.age} years old`);