display array item per second

41 views
Skip to first unread message

aleksand...@rokolabs.com

unread,
Feb 17, 2018, 7:26:38 AM2/17/18
to KnockoutJS
Hello! I have an observable array.I would like display each array item with delay.Is it possible?

Michael Best

unread,
Feb 18, 2018, 1:47:23 AM2/18/18
to KnockoutJS
Of course it's possible.

var delayedArray = ko.observableArray(sourceArray[0]);
var handle = setInterval(function() {
 
if (delayedArray.length >= sourceArray.length) {
    clearInterval
(handle);
 
} else {
    delayedArray
.push(sourceArray[delayedArray.length]);
 
}
}, 1000);

Now you can bind to delayedArray, which will be updated with a new item every second.
Reply all
Reply to author
Forward
0 new messages