Suppose I set up a simple array:
var list = [
"Hello",
"Goodbye",
];
And then I set two variables, one to specify two variables: one for the name of the array, and another for the number, as such:
var array = "list";
var number = 0;
And then I run the following command:
console.log(array[number]);
But it outputs the number "1" instead of "Hello".
Can somebody explain this?
EDIT:
I wrote this question as an inexperienced programmer. What I should have used to complete the task was a dictionary.
They will allow you to, very roughly speaking, index arrays with strings.
var array = "list";?console.log(window[array][number])as window is the global scope.var array = "list";you can get idea what OP want to do here.list. Using bracket notation is a legitimate method to access variables,this[array][number]would have worked as well.