我有一个嵌套数组。我正在使用array.filter从父数组中获取子数组。
我有这样的数据:
"accounts": [
{
"ID": "001yQdmAAE",
"email": "inhome.user@ator.com",
"users": [
{
"Name": "Inhome User",
"MobilePhone": "34877"
}
]
},
{
"ID": "00mAAE",
"email": "in.user@ator.com",
"users": [
{
"Name": "Inhome r",
"MobilePhone": "300077"
}
]
}]
我想根据 ID 从帐户数组中获取用户数组。我试过了array.filter。它返回
{ "ID": "001yQdmAAE",
"email": "inhome.user@ator.com",
"users": [
{
"Name": "Inhome User",
"MobilePhone": "34877"
}
}
我只想要用户数组
const res=this.state.data.filter((res)=>{
if(res.ID==record.ID){
return res.users;
}
});
console.log(res);
米琪卡哇伊
慕沐林林
相关分类