I have an array where I've a name and details array that contains phone numbers and place objects. I am trying to separate the parent array by looping over the inner array. For example I have this array -
const arr = [
{
id: 1,
name: 'Person 1',
details: [
{
phone: 9999999999,
place: 'Mumbai',
},
{
phone: 8888888888,
place: 'Pune'
}
]
},
{
id: 2,
name: 'Person 2',
details: [
{
phone: 7777777777,
place: 'Mumbai',
},
{
phone: 6666666666,
place: 'Pune'
}
]
}
]
I want to convert the array into the result array below, so I can sort, show, and list by ascending phone numbers. I just need to convert the array to the below array result for now -
const result = [
{
id: 1,
name: 'Person 1',
details: [
{
phone: 9999999999,
place: 'Mumbai',
}
]
},
{
id: 1,
name: 'Person 1',
details: [
{
phone: 8888888888,
place: 'Pune'
}
]
},
{
id: 2,
name: 'Person 2',
details: [
{
phone: 7777777777,
place: 'Mumbai',
}
]
},
{
id: 2,
name: 'Person 2',
details: [
{
phone: 6666666666,
place: 'Pune'
}
]
}
]
Please help.