I have array like this
const myArr = [
{
uuid: 123,
name: aa
},
{
uuid: 456,
name: bbb
}
]
How to add a new array if I call API with UUID above this
example: domain.com/product-option/456
I want this response :
const myArr = [
{
uuid: 123,
name: aa
},
{
uuid: 456,
name: bbb,
product-option : [
{
uuid:01,
name: abcd
}
]
}
]
I am assuming when you call an api with any uuid you want to add returned response to that particular item in array.
So lets say you have called api with uuid:456 so you want to include api response into existing array with uuid:456
domain.com/product-option/456
To do that after you get successful api response you can add new property product-option to your existing array myArr using following code -
myArr.forEach((element) => {
if(element.uuid === uuid){
element['product-option'] = response.data;
}
});