dmx dmx - 5 months ago 27
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.


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.