// declared read-only variable:
const support = {
arr: {
ins: ['g3', 'g5', 'g7', 'g10',
'g12', 'g13', 'g14', 'g15'
]
}
},
// object destructuring for easy to call:
{ arr: { ins: supE1range } } = support;
and a function to dynamically change between sup
and 1
in supE1range
object:
function autoSelect(currClass, currElite) {
let setClass = '';
switch (currClass) {
case 'support':
setClass = 'sup';
break;
}
let setObj = `${setClass}E${currElite}range`;
console.log(eval(setObj));
}
autoSelect('support', 1);
as you can see eval(setObj)
will get supE1range
's value because the string is match to the object name.
and now how to accomplish that without eval
?
I've searching related questions/answers but doesn't satisfy want i need.
umm.. don't mind about 'dynamically change' because it's just part of the code that is unnecessary to put here