I want to group details object that have the same value. Details object has a place property. I am trying to group the objects by matching place property.
This is how my Data looks like:
Input
data=[{
"name":"abc",
"age":12,
"details":[{
"place":"abc",
"hobbies":"playing"
}],
"school":"abcd"
},
{
"name":"bcd",
"age":11,
"details":[{
"place":"zyx",
"hobbies":"watching"
}],
"school":"bcda"
},
{
"name":"cde",
"age":13,
"details":[{
"place":"abc",
"hobbies":"playing"
}],
"school":"cdba"
},
{
"name":abcd",
"age":15,
"details":[{
"place":"zyx",
"hobbies":"playing"
}],
"school":"qwer"
}
]
I have tried this using .reduce but unable to group nested array of objects data.
Expected Output
{
'abc': [
{
"name":"abc",
"age":12,
"details":[{
"place":"abc",
"hobbies":"playing"
}],
"school":"abcd"
},
{
"name":"cde",
"age":13,
"details":[{
"place":"abc",
"hobbies":"playing"
}],
"school":"cdba"
}
],
'zyx': [
{
"name":abcd",
"age":15,
"details":[{
"place":"zyx",
"hobbies":"playing"
}],
"school":"qwer"
},
{
"name":"bcd",
"age":11,
"details":[{
"place":"zyx",
"hobbies":"watching"
}],
"school":"bcda"
},
]
}
Kindly help me in solving this problem.