There is a condition where i need to convert Array of objects into Array of Arrays. An array is given below as data convert this array as formatedArray.
data = [
{
"total": 1,
"third": 0,
"city": "Agra",
"first": 0,
"second": 0
},
{
"total": 2,
"third": 0,
"city": "Agra",
"first": 0,
"second": 0
},
{
"total": 3,
"third": 0,
"city": "Delhi",
"first": 0,
"second": 0
},
{
"total": 4,
"third": 0,
"city": "Delhi",
"first": 0,
"second": 0
}
]
How can I convert the array of objects above into an array of arrays below?
formatedArray=[
"Agra":[
{
"total": 1,
"third": 0,
"city": "Agra",
"first": 0,
"second": 0
},
{
"total": 2,
"third": 0,
"city": "Agra",
"first": 0,
"second": 0
}
],
"Delhi":[
{
"total": 4,
"third": 0,
"city": "Delhi",
"first": 0,
"second": 0
},
{
"total": 4,
"third": 0,
"city": "Delhi",
"first": 0,
"second": 0
}
]
]
arrays. )