-2

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"}
]
eggshot
  • 190
  • 6

2 Answers2

1

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); });
anthonybell
  • 5,790
  • 7
  • 42
  • 60
0

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.

Max Hartshorn
  • 709
  • 7
  • 19