js取json中数组中指定的内容
eg:
json数据为{[{name:a,age:18,sex:male},
{name:b,age:22,sex:male},
{name:c,age:27,sex:female},
{name:d,age:23,sex:female},
{name:e,age:19,sex:male}]
}
最后希望的数据为name数组:[a,b,c,d,e]
sex数组:[male,male,female,female,male]
请问js语句该怎么写呢?
回答
let names = [];
let sexs = [];
for(let i=0;i<json.length;i++){
names[i] = json[i]["name"];
sexs[i] = json[i]["sex"];
}
以上是 js取json中数组中指定的内容 的全部内容, 来源链接: utcz.com/a/64483.html