I have a string like this:
let user = "req.user.role"
is there any way to convert this as nested objects for using in another value like this?
let converted_string = req.user.role
I know I can split the user with user.split(".")
my imagination :
let user = "req.user.role".split(".")
let converted_string = user[0].user[1].user[2]
I found the nearest answer related to my question : Create nested object from query string in Javascript
reqas a dynamic variable name. It would need to be a property of another object ( even window) and use[]notation for all[user[0]][user[1]][user[2]](you should use bracket notation), but you will still getundefined, despite the fact, there is no value for the property that you looking for.reqis hard coded or a known object reference