There are no associate arrays in JavaScript so to speak. In JavaScript arrays are one dimensional, you retrieve items based on their index within the array. You are talking about objects or object literals. I've coded an example and example structure for you below.
var saveObj = {}; //Setup a blank object for the data;
$("#banners tbody tr").each(function () {
var id = $('td:first', $(this)).text();
saveObj[id] = {
name : $('td:nth(1)', $(this)).text(),
pos : $('td:nth(2)', $(this)).text(),
url : $('td:nth(3)', $(this)).text(),
loc : $('td:nth(5)', $(this)).text()
};
});
This sets up a blank object literal first called saveObj
. This is your blank canvas so to speak. Then within your loop you are grabbing the id as normal. This will be your key within the object and the value for the key will be another object literal which we create dynamically within the loop. using the same keys as your variables (name, pos, url, loc) with their data values in the same way you are grabbing them now. Your structure will be like this
var saveObj = {
"12" : {
name : "YourName",
pos : "YourPos",
url : "YourUrl",
loc : "YourLoc"
},
"16" : {
name : "YourName2",
pos : "YourPos2",
url : "YourUrl2",
loc : "YourLoc2"
}
};