node package manager

list-cycler

Inifinity cycle through list.

node-list-cycler

Infinity cycle through list

npm install list-cycler

Iterate from beginning of list:

var cycler = require("list-cycler"),
    colors = cycler(['red', 'green', 'blue']),
    color,
    i=6;
while (--i) {
    color = colors.next();
    console.log(+ '. <span color="' + color + '">' + color + '</span>');
}

If should start from index other then 0 - here iterate from index 1 (letter 's') - look at second argument to cycler:

var cycler = require('list-cycler'),
    colors = cycler(['red', 'green', 'blue'], 1),
    color,
    i=6
 
while (--i) {
    color = colors.next();
    console.log(+ '. <span color="' + color + '">' + color + '</span>');
}