I have some data from a collection named "service" which has data like this:
let service_data = [
{
"name":"Service 1",
"price":60,
"resource_group_ids" :
["5d5e5dea99d9b75ff2f78dcd","5d5e85d329782914332368c8"]
},
{
"name":"Service 2",
"price":60,
"resource_group_ids" : ["5d5e5dea99d9b75ff2f7cfe"]
}
]
I want to push the resource_group_ids in a variable let say resource_groups. I don't want to loop resource_group_ids inside service_data.
You can use flatMap
or reduce on older environments
You could use
flatMap
If
flatMap
is not supported, useconcat
and spread syntax to merge the 2D array returned bymap
Using
.reduce
:You can achieve this with
.map()
,.join()
and.split()