Without using eval ... I'm trying to see if I can get a value from a variable where the value is stored in another variable. Such as get value of 'ValueC' from varA where varA='varB' and varB='ValueC'
The user will enter a string, simulated below as the variable named 'UserSpecified'. They could enter any character and if doesn't match an existing variable ... well I'll just return null.
I realize I can do this with an eval(), but evals seem to be frowned upon I'm trying to do it in a better way.
I've tried the ES2015+ accepted answer from "Variable" variables in Javascript? but I'm not having any success. Am I missing something or should I stick with an eval?
let a = "aye";
let b = "be";
let c = "sea";
let userSpecified="a";
let obj = {userSpecified};
let parm='userSpecified';
console.log(eval(userSpecified)); // This displays 'aye'
console.log(obj[parm]); // This displays 'a' but I would like it to display 'aye'