title: How to convert json encoded PHP array to an array in Javascript?
body: <p>I am fetching a JSON encoded array using AJAX from a PHP file, but in JavaScript I need to use it as an array, how can I create an array in Javascript?</p>
  
  <blockquote>
    <p><strong>My AJAX call to PHP File:</strong></p>
  </blockquote>
  
  <pre><code>  $.ajax({
      type:"POST",
      url:"ajaxfetch.php",
      success:function(result){
              alert(result);
               }
      });
  </code></pre>
  
  <blockquote>
    <p><strong>ARRAY Created in PHP File :</strong></p>
  </blockquote>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [id] =&gt; 4
              [deviceID] =&gt; xyz123
              [latitude] =&gt;  -33.80010128657071
              [longitude] =&gt; 151.28747820854187
              [altitude] =&gt; 34.78788787
              [createdDate] =&gt; 2013-08-15 23:00:00
              [delete] =&gt; 0
          )
  
      [1] =&gt; Array
          (
              [id] =&gt; 5
              [deviceID] =&gt; jdkfhjskh344
              [latitude] =&gt; -33.950198
              [longitude] =&gt; 151.259302
              [altitude] =&gt; 76.44455
              [createdDate] =&gt; 2013-08-15 21:50:42
              [delete] =&gt; 0
          )
  
      [2] =&gt; Array
          (
              [id] =&gt; 1
              [deviceID] =&gt; abc223
              [latitude] =&gt; -33.890542
              [longitude] =&gt; 151.274856
              [altitude] =&gt; 21.4454455
              [createdDate] =&gt; 2013-08-15 20:00:00
              [delete] =&gt; 0
          )
  
  )
  </code></pre>
  
  <p><strong>I json encoded this array in PHP</strong> but AJAX retrieved it and is outputted <strong>in a string</strong>.</p>
  
  <blockquote>
    <p><strong>ABOVE ARRAY json encode as given below:</strong></p>
  </blockquote>
  
  <pre><code>$data = array();
  $data = $locate_obj-&gt;getAllDeviceLocation();
  
  
  echo json_encode($data);
  </code></pre>
  
  <blockquote>
    <p><strong>Output of json_encode</strong></p>
  </blockquote>
  
  <pre><code>[{"id":"4","deviceID":"xyz123","latitude":" -33.80010128657071","longitude":"151.28747820854187","altitude":"34.78788787","createdDate":"2013-08-15 23:00:00","delete":"0"},{"id":"5","deviceID":"jdkfhjskh344","latitude":"-33.950198","longitude":"151.259302","altitude":"76.44455","createdDate":"2013-08-15 21:50:42","delete":"0"},{"id":"1","deviceID":"abc223","latitude":"-33.890542","longitude":"151.274856","altitude":"21.4454455","createdDate":"2013-08-15 20:00:00","delete":"0"}]
  </code></pre>
  
  <p>I'm looking for the way I can create an array in Javascript with the output I recieve in ajax response, so that I can come up with an array of format:</p>
  
  <pre><code>var locations = [
        ['Bondi Beach', -33.890542, 151.274856, 4],
        ['Coogee Beach', -33.923036, 151.259052, 5],
        ['Cronulla Beach', -34.028249, 151.157507, 3],
        ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
        ['Maroubra Beach', -33.950198, 151.259302, 1]
      ];
  </code></pre>