var a = [10,20,30,40];
var b = [11,22,33,44];
var c = [40,30,20,10];
var d = ["a","b","c"];
var e = d[2];
console.log(e[0]);
How do I make javascript treat string value of variable e (i.e. string 'c') as name of array so e[0] would return 40 and not the character at position [0]. Thank you for your support and sorry if it's a dumb question.
Instead of string put the reference of the array as the element.
var d = [a, b, c];
var a = [10, 20, 30, 40];
var b = [11, 22, 33, 44];
var c = [40, 30, 20, 10];
var d = [a, b, c];
var e = d[2];
console.log(e[0]);
eval() method but I don't prefer that method.
Refer : Why is using the JavaScript eval function a bad idea?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With