title: Uncaught TypeError: Cannot read property '0' of undefined yii2, JSON, AJAX, Array
body: <p>I am trying to highlight all the dates that have been scheduled. Ajax and JSON working correctly, I get all the results on console.log(), except for this error when I try to go through the array. But the array has data in it and shows up on console.log. What am I doing wrong? Please help!!!!</p>
  
  <pre><code>'beforeShowDay'=&gt; new JsExpression
      ('  
              function(date) { 
          $.ajax({
                  url: "taskslist",
                  dataType: "json",
          data: 
              {
                  id: '.$CERTIFICATION_PERIOD_ID.',
              },
      success: function(data) 
              { 
                  jQuery.parseJSON = function( data ) 
                      {
                          return JSON.parse( data + "" );
                      };
  
              if (data !== null) 
                  {   
  
                      var TaskScheduleEmployee = [];
                      var TaskScheduleDates = [];
  
                      $.each(data, function (index, task)
                              {
                              var TASK_SCHEDULE_DATE = task.TASK_SCHEDULE_DATE;
  
                                  var EMPLOYEE_ID = task.EMPLOYEE_ID;
                              }
  
                          );
  
  
                  TaskScheduleDates = $.map(data, function(task)
                                              { return task.TASK_SCHEDULE_DATE;
                                              }
                                            );
                  TaskScheduleEmployee = $.map(data, function(task)
                                              { return task.EMPLOYEE_ID;
                                              }
                                            );
  
                          for (var i = 0; i &lt; TaskScheduleDates.length; i++) 
                              {
  
                                  var d = date.getDate();
                                  var m =  date.getMonth();
                                  m += 1;  // JavaScript months are 0-11
                                  var y = date.getFullYear();
  
                                  var dateToCheck = (y + "-" + m + "-" + d);
                                      if (TaskScheduleDates[i] == dateToCheck) 
                                          {
                                              return [true, "ui-state-highlight", TaskScheduleEmployee[i]];
                                          }
                              }
                          return [true, ""];
  
  
                  }
              else 
                  {
                      alert("We are sorry, we couldnot load the Episode");
                  }
          }
  });
  
  
  
  
          }
  '),
  </code></pre>