How am I going to access the firstnames or the lastnames?
[
{name:"Name",value:{firstName:"John",lastName:"Doe"},
{name:"Name",value:{firstName:"Juan",lastName:"delaCruz"}
]
How am I going to access the firstnames or the lastnames?
[
{name:"Name",value:{firstName:"John",lastName:"Doe"},
{name:"Name",value:{firstName:"Juan",lastName:"delaCruz"}
]
there's a typo in your code (the closing braces).
z = [
{name:"Name",value:{firstName:"John",lastName:"Doe"}},
{name:"Name",value:{firstName:"Juan",lastName:"delaCruz"}}
];
firstPersonsName = z[0].value.firstName
allFirstnames = z.map(function(n) { console.log(n.value.firstName); });
allLastnames = z.map(function(n) { console.log(n.value.lastName); });
Assuming your array is named arr
, you can access first names with arr[i].value.firstName
and last names with arr[i].value.lastName
where i
is the array index of the item you want to access.