A much more efficient method is to move the subscript of the array. When the subscript reaches the end, it goesback to the beginning. The number to be delayed is added at thevalue of the subscript just after the old, delayed value is extracted. Only one box of the array is manipulated, and this is a great savings when there are many boxes.
You may ask why it matters to save some execution time for the CPU when computers have fantastic speed now a days. Consider using many boxes in the array to get precision of the delayed value. We may wish to update several thousand times per second. That would mean many unneeded computations when using the array that must be reshuffled each time there is a new entry.
var stack = ; stack.push(2); // push adds 2 to end of stack stack.push(5); // push adds 5 to end of stack var i = stack.pop(); // get top of stack OR var i = stack.pop(n); //get nth entry of big stack