I have an array
[
{
"offerId": "123",
"offerStatus": "ACTIVATED",
"products": [
{
"productId": "1"
}
]
},
{
"offerId": "456",
"offerStatus": "NOT_ACTIVATED",
"products": [
{
"productId": "2"
},
{
"productId": "3"
}
]
}
]
Want to push(copy) offerStatus into product object, so the expected output is
[
{
"offerId": "123",
"offerStatus": "ACTIVATED",
"products": [
{
"productId": "1",
"offerStatus": "ACTIVATED"
}
]
},
{
"offerId": "456",
"offerStatus": "NOT_ACTIVATED",
"products": [
{
"productId": "2",
"offerStatus": "NOT_ACTIVATED"
},
{
"productId": "3",
"offerStatus": "NOT_ACTIVATED"
}
]
}
]
Map the array, use the
withSpecutility function (based on this answer) to update theproductsusing theofferStatusof the parent. Then map products, and merge the currentofferStatus: