I understand how recursion works, but I stuck with problem iterate throw this data view and replace all propertirties that called innerArray with subArray
I have next data view
const data = [
{name: 'First', innerArray: [{name: InnerFirst, innerArray: []}]},
{name: 'Second', innerArray: []}
]
And I try to transform in to next view
const data = [
{name: 'First', subArray: [{name: InnerFirst, subArray: []}]},
{name: 'Second', subArray: []}
]
There are another ways to make it, but how solve this task with recursion appoach?
function transformData = (data) => {
for(let i =0; i< data.length; i++) {
if(data[i].innerArray && data[i].innerArray.length) {
//replace property
} else {
transformData()
}
}
}
console.log(transformData(data))
InnerFirst? Is that supposed to be a string?