My data structure consists of an associative array indexed by dates, with each element containing another array.
[03/16/2015: Array[3], 03/17/2015: Array[3], 03/18/2015: Array[3], 03/19/2015: Array[3]]
The array was created using the following code:
array[cellDate][i]=cellText;
I am trying to retrieve a specific value from the array, for instance, cell 03/16/2015 array[2]. However, when I use this line of code:
var text=array['03/16/2015'][2];
An error occurs.
EDIT:
In this array, I store titles of blocks on the schedule, assigning 'empty' if the cell is empty.
My goal is to maintain the order of blocks for different weeks and dynamically load blocks based on the date withdrawn from the array when the user navigates through weeks.
The function used to create the array is as follows:
function saveWeekToArray(array){
var cellDate;
var cellText;
var tmpText;
var i;
workoutsTD.each(function(){
cellDate=$(this).attr("data-day");
array[cellDate]=['','',''];
i=0;
$(this).children('.workout-cell').each(function(){
if (!$(this).hasClass('workout-cell-empty')){
cellText=$(this).find('span').text();
array[cellDate][i]=cellText;
} else {
array[cellDate][i]='empty';
}
i++;
});
});
}
The function that loads data from the array (the one causing the error) is as follows:
function loadBlocksFromArray(array){
var cellDate;
var cellText;
var tmpText;
var i;
workoutsTD.each(function(){
cellDate=$(this).attr("data-day");
i=0;
$(this).children('.workout-cell').each(function(){
if ((array[cellDate][i])!='empty'){
cellText=array[cellDate][i];
$(this).append(createBlock(cellText));
$(this).removeClass('workout-cell-empty');
}
i++;
});
});
}
If you click submit button, the console log will display the structure of the array.
The error I encounter while changing weeks is:
enter code here
Uncaught TypeError: Cannot read property '0' of undefined