-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"}
]
4

2 回答 2

1

您的代码中有错字(右大括号)。

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); });
于 2013-09-14T04:11:29.687 回答
0

假设您的数组是 named arr,您可以访问 first names witharr[i].value.firstName和 last names with arr[i].value.lastNamewherei是您要访问的项目的数组索引。

于 2013-09-14T04:00:49.067 回答