I have an array
[
{
"id": 19,
"name": "rice",
"food_group": null,
"created_at": "2022-03-15T02:38:17.911Z",
"updated_at": "2022-03-15T02:38:17.911Z"
},
{
"id": 20,
"name": "water",
"food_group": null,
"created_at": "2022-03-15T02:38:17.942Z",
"updated_at": "2022-03-15T02:38:17.942Z"
},
{
"id": 8,
"recipe_id": 19,
"ingredient_id": 19,
"quantity": 1,
"measurement_unit": "cup",
"created_at": "2022-03-15T02:38:17.932Z",
"updated_at": "2022-03-15T02:38:17.932Z"
},
{
"id": 9,
"recipe_id": 19,
"ingredient_id": 20,
"quantity": 23,
"measurement_unit": "cup",
"created_at": "2022-03-15T02:38:17.945Z",
"updated_at": "2022-03-15T02:38:17.945Z"
}
]
And I want to reduce these objects down to two objects that represent the ingredient and measurements, making it displayable. Since the ingredient_id is available in the measurement/quantity object I believe this is doable, but I am struggling to see how to do this.
I have a sandbox here where I've been trying
So ideally the array would become
[{"rice": { "measurement_unit": cup, quantity: 1}}...]