title: How to fix Uncaught TypeError: Cannot read property '0' of undefined
body: <p>i would like to send my data from mssql via php to my chart. For this i'm using <code>$.get</code> function to receive data from mssql.
  but i'm getting an error: <code>Uncaught TypeError: Cannot read property '0' of undefined</code> obviously i can't access an object.</p>
  
  <p>my php code:</p>
  
  <pre><code>if(isset($_GET['employeesChart'])) {
      getemployeesChart($conn);
  }
  
  function getemployeesChart($conn) {
    $sql ="SELECT * FROM employee;
    $result = sqlsrv_query($conn, $sql);
    $row = sqlsrv_fetch_array($result);
    $isAtWork = $row['Work'];
    $isAtHome = $row['Home'];
    $data = array('isAtWork' =&gt; $isAtWork, 'isAtHome' =&gt; $isAtHome);
    echo json_encode($data)
  }
  </code></pre>
  
  <p>and my javascript code:</p>
  
  <pre><code>var data = {
      labels: [
          "Home",
          "Work",
          "Break"
      ],
      datasets: [{
          data: [],
          backgroundColor: ["#FF6384","#36A2EB","#FFCE56"],
          hoverBackgroundColor: ["#FF6384","#36A2EB","#FFCE56"]
      }]
  };
  
  $.get("employees.inc.php?employeesChart", function(data){
      var result = $.parseJSON(data);
      var test = data.datasets[0].data.push(result[0],result[1]);
      myDoughnutChart.update();
  });
  
  // Doughnut Chart
  var myDoughnutChart = new Chart(ctx, {
      type: 'doughnut',
      data: data,
      options: {
              responsive: true,
              legend: {
                  position: 'right',
              },
              animation: {
                  animateScale: true,
                  animateRotate: true
              }
          }
  });
  </code></pre>
  
  <p>i don't understand why do i get an error. When i test it with <code>console.log(result)</code> im getting two integers but the code sample make <code>data.datasets[0].data.push(result[0],result[1])</code> an error</p>