I am trying to get values from nested arrays using Ramda. I have multiple groups like in the example below. I need to get all children from all sections and all childrenWithoutSections in one array of strings.
const groups = [
{
"id":"10",
"sections":[
{
"id":"1",
"children":["10", "11"]
},
{
"id":"2",
"children":["12"]
}
],
"childrenWithoutSections":["1", "2"]
},
{
"id":"11",
"sections":[
{
"id":"3",
"children":["13", "14"]
},
{
"id":"4",
"children":["15"]
}
],
"childrenWithoutSections":["3", "4"]
}
]
I started with something like this:
R.pipe(
R.pluck(['childrenWithoutSections']),
R.flatten
)(groups)
And as a result, I got all the children from one required key but I have no idea how to get nested values from sections/children?
groups .flatMap (g => [... g .sections .flatMap (s => s.children), ... g . childrenWithoutSections])?R .chain (g => R .chain (s => s.children, g .sections) .concat (g . childrenWithoutSections), groups)