dmx dmx - 1 year ago 88
JSON Question

Get json item one by one

Is it possible to loop a json object one by one ?

let's say I have this object (text). I want to loop on

and get next item every 1 minute until I get them all. How can I do this in javascript ?

var text =
"name":"John Johnson",
"street":"Oslo West 16",
"determine":"555 1234567",

}, 1000);

sorry if it is duplicated I have not found solution.

Answer Source

You can use Object.keys if the order is not important:

var keys = Object.keys(text), i = 0;

var myInterval = setInterval(function(){
   if(i >= keys.length) clearInterval(myInterval); // You need to clear the interval ;) 
   var current = text[keys[i++]];
}, 1000*60); //1 minute

I hope this will help you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download