I have a collection of unorganized JavaScript objects with similar keys but potentially different values. For example:
const raw_data = {
"sweets":[
{
"flavor":"chocolate",
"product":"icecream",
"price":3
},
{
"flavor":"vanilla",
"product":"icecream",
"price":3
},
...
]
}
I need to transform this data into a new organized object where the unique values from the flavor
variable become keys, each holding an array of objects with matching flavor values. Here's an example of the desired output:
const cleaned_data = {
"chocolate": [
{
"flavor":"chocolate",
"product":"icecream",
"price":3
},
...
],
"vanilla": [
{
"flavor":"vanilla",
"product":"icecream",
"price":3
},
...
],
...
}
If anyone has a function that can achieve this transformation without using external libraries, please share!