Dave Appleton Dave Appleton - 1 year ago 168
Javascript Question

iterate though JSON array in p5.js

I have a server that returns :
JSON Image

I want to iterate through this data in p5.js

var ms = []

function preload() {
var url ='https://dest/url'
ms = loadJSON(url)

Which I expected to return an array but it does not seem to return anything sensible.

Chrome debug of JSON

However, if I paste the same data into the Javascript console I get different data :

pasted JSON

How do I either iterate over this data (it is NOT loaded as an array) or convert it to an array?

Answer Source

I think you mean this:

var array;
for (var key in ms) {
   if (!array) {
      array = [a[key]];
   } else {
console.log(array); // [ {'time': .... }, {...}, .. ]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download