How to write the best javascript function for getting this output.
['1','p1','p11','2','p2','p21']
for this input.
const arr = [{
"children": [{
"property1": "1",
"children": [{
"property1": "p1",
"children": [{
"property1": "p11",
"children": [
]
}]
}]
}]
},
{
"children": [{
"property1": "2",
"children": [{
"property1": "p2",
"children": [{
"property1": "p21",
"children": [
]
}]
}]
}]
}
]
How to get the output using recursive function. It is loop of children. if the children length is 0 then don't add otherwise add arrays of property1.