var items = [
{
text: "foo",
delay: 0
},
{
text: "bar",
delay: 2000
}];
printAsync();
function printAsync() {
var delay = 0;
items.forEach(item=>setTimeout(function() {
console.log(item.text)
}, item.delay))
}
https://jsfiddle.net/ddo259tv/var textArray = [{
"text": "foo",
"delay" : "2000"
},
{
"text": "bar",
"delay" : "2000"
}];
(function one(i) {
console.log(textArray[i].text);
setTimeout(function() {
one(i+1);
}, textArray[i].delay)
})(0);