I would like to be able to reference an array by using a string, as such:
var arrayName = "people";
var people = [
'image47.jpeg',
'image48.jpeg',
'image49.jpeg',
'image50.jpeg',
'image52.jpeg',
'image53.jpeg',
'image54.jpeg',
'image55.jpeg',
]
function myFunc (arrayName)
{
//arrayName is actually just a string that evaluates to "people", which then in turn would reference the var people, which is passed in.
}
Any thoughts on how to do this? Sorry if I’m missing something obvious.
You can simply create a global dictionary, like this:
Note that the first line of myFunc makes it clear that this is just a complicated way of having
myFuncaccept the array itself in the first place. I strongly suggest that you do just that, like this:This means that your code will be reusable by anyone else (say, a third-party plugin that wants to render giraffes) and not require any global variables.