I wish to name an array according to the table row containing the button that was clicked.
I get the table row thus:
var rowNum = $(this).parent().parent().index();
Now, I wish to name the array and access it.
var arrayName = 'arrTR' + rowNum;
window[arrayName] = new Array();
window[arrayName]["First"] = "Bob";
window[arrayName]["Last"] = "Roberts";
window[arrayName]["email"] = "[email protected]";
//The array should be accessible as arrTR__
alert(arrTR1["Last"]);
The alert does not work, so I am doing something wrong.
How should I refactor the code to allow me to update and access the array?
datamethod and store it in the$.cacheif you want a global variable.arrTR1variable. But why are you creating global variables like that? If you explain what you're trying to achieve somebody will suggest a better way. As an aside: don't use arrays with non-numeric properties, you should use objects:window[arrayName] = {}.datamethod and storing in the$.cache?datamethod, jQuery uses the$.cacheinternally. So all you need to know is how to use thedatamethod. I've updated my answer