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"}
]
您的代码中有错字(右大括号)。
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); });
假设您的数组是 named arr
,您可以访问 first names witharr[i].value.firstName
和 last names with arr[i].value.lastName
wherei
是您要访问的项目的数组索引。