I have a path of the child object in a parent object. This path is combination of arrays and objects
const path = ['one', 'two', '0', 'three', '2'];
and parent object will be
const root = {
'one' : {
'two': [
{
'three': [
{},
{},
{
'deleterObject': 'yes'
}
]
},
[], []
],
c: [],
d: []
}
}
after doing this execution, final output should look like,
const root = {
'one' : {
'two': [
{
'three': [
{},
{}
]
},
[], []
],
c: [],
d: []
}
}
function that I wrote is,
const deleteObject = (root, path) => {
let concated = '';
for(let child in pathArray) {
if(child > 0) concated = concated.concat(`[${pathArray[child]}]`)
else concated = `[${pathArray[child]}]`
}
delete concated;
return root
}
But its returning an error, Please suggest some function to do this.