I'm facing a challenge here. I have a function that accepts a path and also need to condition it with a variable.
Here's the issue: I want to create a string type that will serve as an access point for my variable.
In this case, I have a roles.operation
variable that I aim to access dynamically.
The roles variable contains an array with values including:
roles.operations = ['document','article','document-type'];
Using this variable dynamically is my goal.
This is what I attempted, where in the replacePath I have the value of document-type:
export const createVariable = (roles,path) => {
const replacePath = path.replace(/-/g,"_");
const finalPath = window[`roles.operations.${replacePath}`];
console.log(finalPath);
}
However, this returned undefined.