Mike B Mike B - 12 days ago 7
Javascript Question

Why is it when I'm downloading my array and try to get the length of it, it just spits out the number of bytes the array is

When I use the jQuery library to download an array and get the length of it using native javascript, it just spits out the total amount of bytes of the array, like so:



$.get({
url: 'https://rawgit.com/tvman-123/shrek/master/ExampleOutputForSubscription_Post.php', //
data: {},
success: function(data) {
ParseData(data);
}
});


function ParseData(data) {
console.log(data.length) //Returns 221
}

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>





But when I include the array inline, it works like it's supposed to, like so:



data=["UU9CuvdOVfMPvKCiwdGKL3cQ","UUrTNhL_yO3tPTdQ5XgmmWjA","UUz-RZblnhjXK_krP1jDybeQ","UUc_xdkOBgSYLmXTn-VSQ4uA","UUmb8hO2ilV9vRa8cilis88A","UU45SDrjKlPSY0bTvH6F7TOA","UUdGkmb5zEDXnPSmQlV43t0Q","UUpeGBKn0axOJAcPHkcPiXcg",""]
ParseData(data)

function ParseData(data){
console.log(data.length)//Returns 9
}

<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>





My understanding is that the first one is a byte array and the second one is an arraylist.

Can someone please explain to me why its doing this and how to fix it???

EDIT:

Thank you all for your answers, and helping me fix this problem

Answer

the type of data received is JSON! add dataType: "json"

$.get({
  url: 'https://rawgit.com/tvman-123/shrek/master/ExampleOutputForSubscription_Post.php', //
  data: {},
  dataType: "json",
  success: function(data) {
    console.log(data.length); // data is parsed.. =)
  }
});