Fork me on GitHub

View source on github.

original array : []

//conventional use (as if it was a for or for as loop)
test.foreachLoopBack(function(elem){document.getElementById('conventional').innerHTML += elem});

//same but reverse (note the true in second argument)
test.foreachLoopBack(function(elem){document.getElementById('conventional-reverse').innerHTML += elem}, true);

//from index 3 - this will loopback at the end of the array if no indexStop specified
test.foreachLoopBack(function(elem){document.getElementById('from-3').innerHTML += elem}, false,3);

//from index 3 - same as before, but reverse
test.foreachLoopBack(function(elem){document.getElementById('from-3-reverse').innerHTML += elem}, true,3);

//from index 3 to index 8
test.foreachLoopBack(function(elem){document.getElementById('from-3-to-8').innerHTML += elem}, false,3,8);

//from index 3 to index 8 - reversed
test.foreachLoopBack(function(elem){document.getElementById('from-3-to-8-reverse').innerHTML += elem}, true,3,8);

//from index 8 to index 3 - will loopback at the end of the array
test.foreachLoopBack(function(elem){document.getElementById('from-8-to-3').innerHTML += elem}, false,8,3);

//from index 8 to index 3 - reversed
test.foreachLoopBack(function(elem){document.getElementById('from-8-to-3-reverse').innerHTML += elem}, true,8,3);