Javascript adding array to specific index
<p>When i have the following global variable on my application start :</p>

<p><code>events = [];</code></p>

<p>Then if i go fetch something with ajax with the following simplified code snippet :</p>

<pre><code>events[0] = [];

setTimeout(function fetchEventsThisWeek(){

    $.ajax({
      url: '/event/getEventsBetweenDates',
      type: 'POST',
      data : { from_date : currentweek.from_date.toString("yyyy-MM-d") , to_date :  currentweek.to_date.toString("yyyy-MM-d"), limit : limit, offset : offset },
      success: function(data) {
            jQuery.each(data, function(index){
                events[0].push(data[index]['attributes']);
            });




            offset = offset + limit;
            entry_count = entry_count + data.length;

            if(data.length &lt; limit) { // We reached the end of the table so we don't need to call the function again
                renderEvents(current, offset - limit, entry_count);
                //Make sure the current next week button gets enabled because we are done with the results

            } else {
                renderEvents(current,  offset - limit, offset);
                setTimeout(fetchEventsThisWeek, 150); // There are more results, continue
            }

      }
    })
}, 150);
</code></pre>

<p>This recursive function just fetches all events between two dates and keeps calling itself until there is no record in the db left.
My problem is:</p>

<p>With the variable:</p>

<pre><code>events[0] = [];
</code></pre>

<p>I want to specify the index of the array as my week entry. So if i look for a specific week, i can get all the entries that already have been fetched from my array by the array index.</p>

<p>My problem is, when i want to fetch more weeks, so for example:</p>

<pre><code>events[1] = [];// Index 1 would represent the next week
</code></pre>

<p>The array just expands in size and all gets appended to the end, so i  have one big array and not a multidimensional one. Why is this? And how can i achieve this behaviour?</p>

<p>Edit:
Let me expand on my question.</p>

<p>I need several arrays of json objects in the events variable.
So..</p>

<pre><code>events[0] = [ /*contains array of json objects */];
events[1] = [ /*contains array of json objects */];
events[2] = [ /*contains array of json objects */];
</code></pre>

<p>Each array index represent 1 week. So index 0 is the current week, index 1 is week 1, index 2 is week 2 and so forth. I even want to do the following but i don't know if this is even possible:</p>

<pre><code>events[-1] = [ /*contains array of json objects */];
</code></pre>

<p>Where the index -1 would be 1 week in the past. Could anybody let me know if this is possible?</p>
