I have the people data below. where in people data there is "dataInduk" and inside "dataInduk" there is "dataAnak". how can I find people id data if I have "idAnak". this is my code
const people = [
{
name: 'James',
id: 1,
dataInduk: [
{
idInduk: '1a',
dataAnak: [
{
idAnak: '1a1'
},
{
idAnak: '1a2'
}
]
},
{
idInduk: '1b',
dataAnak: [
{
idAnak: '1b1'
},
{
idAnak: '1b2'
}
]
}
]
},
{
name: 'John',
id: 2,
dataInduk: [
{
idInduk: '2a',
dataAnak: [
{
idAnak: '2a1'
},
{
idAnak: '2a2'
}
]
},
{
idInduk: '2b',
dataAnak: [
{
idAnak: '2b1'
},
{
idAnak: '2b2'
}
]
}
]
}
];
for example:
when i find from idAnak = ‘2b2’ then show id "2" from people
2
Answers
You can map your people
array
withforEach
to get the result you wantOne liner: