There is an object like:
props = {
any: 'thing',
intro: { content: 'foo' }
}
Now I want to loop through a given string representing a specific path (props.intro.content) in a way to set the deepest value to undefined:
props.intro.content = undefined
props.intro = undefined
props = undefined
So the results by iterating the path given above should output these three objects:
{
any: 'thing',
intro: { content: undefined }
},
{
any: 'thing',
intro: undefined
},
undefined
I tried to use split and for loop
const array = 'props.intro.content'.split('.')
for (let index = array.length - 1; index > -1; index--) {
console.log([array.join('.')]) // this returns the flatten path
array.pop()
}
but this doesn't handle the object itself, so I do not get the correct object as output.