I have this Object which I want to restructure as shown in the desired output below. The IngriId in desired output is just Date.now() I am struggling to rearrange this it seems impossible to me .Can this be done in javascript because I am very new to it and I am finding it hard to implement?
Input:
const Shopping = {
"meatsOutput": [
{
"val": "Chicken breast"
}
],
"spicesOutput": [
{
"amount": "½ tsp",
"val": "paprika"
}
],
"dairyOutput": [
{
"amount": "1/2 Cup",
"val": "yogurt"
},
{
"amount": "1/2 teaspoon",
"val": "heavy cream"
}
]
}
Desired Output:
const ShoppingList = [
{
"data": [{
"value": "Chicken breast",
"ingrId": "202237423fm16787",
}],
"name": "meatsOutput",
},
{
"data": [{
"amount": "½ tsp",
"value": "paprika",
"ingrId": "20223742381r787",
}],
"name": "spicesOutput",
},
{
"data": [{
"amount": "1/2 Cup",
"value": "yogurt",
"ingrId": "202237423816787",
}, ],
"name": "dairyOutput",
}
]
ingrIdcome from?Date.now()dairyOutputwhen there are two ingredients?