Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Help with JSON raw format in javascript

I have a JSON array of data which is

[ [[2, 5], [6, 10], [10, 7], [11, 15]],
  [[0, 9], [1, 16], [3, 19], [4,  15]],
  [[0, 7], [5, 16], [8, 17], [12, 19]] ]

but when I try to get the first array of [[2, 5], [6, 10], [10, 7], [11, 15]] using jsonData[0] I get the data as 2,5,6,10,10,7,11,15.

I would like to get the data in the JSON format and not the plain text format. Any ideas?

like image 871
Sana Avatar asked Mar 03 '26 20:03

Sana


1 Answers

You should get the data as an array. Did you alert jsonData[0] because that will display the results as a flattened string.

Instead console.log(jsonData[0]) to see the actual array.

Here's the output I see when using your array.

var a = [[[2, 5], [6, 10], [10, 7], [11, 15]],[[0, 9], [1, 16], [3, 19], [4, 15]],[[0, 7], [5, 16], [8, 17], [12, 19]]];

alert(a[0]);       // 2,5,6,10,10,7,11,15

console.log(a[0]); // [[2, 5], [6, 10], [10, 7], [11, 15]]

See an example.

Also, "JSON raw format" is misleading. What you have is a plain JavaScript array.

like image 197
Anurag Avatar answered Mar 05 '26 09:03

Anurag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!