I'm trying to convert a string into a variable name, in this case an array. Normally I would do it with window[var], but I'm working inside jQuery:
$(function() {
var myArray = new Array();
var myArrayName = 'myArray';
console.log(window[myArrayName]); // undefined
});
that doesn't seems to work, because myArray is located inside the jQuery scope.
I'm aware that I could declare myArrayName as a global variable to access it from everywhere, but I don't want to do that because I want to avoid the global namespace pollution.
is there a way to convert a string into a variable inside jQuery?