How does the cycle that mimics the shift method?

FuncShift write a function that emulates the behavior of the shift function, pressing the button creates a new array where the zero element is the first element of the original array.

let a = [4,5,6];
funcShift function() {
 let b = [];
 for (let i = 1; i < a.length; i++) {
 b[i-1] = a[i]
 a = b;
 document.querySelector('.out-8').innerHTML = a;

document.querySelector('.result-8').onclick = funcShift;

Please explain the operation of this cycle. Thank you!
April 3rd 20 at 18:55
2 answers
April 3rd 20 at 18:57
Go through the array a to the end, starting from element with index 1, in this case 5-RCA. Record this five in the array b at the first(zero) position. Repeat all the same another iteration. Thus, we obtain an array b = [5, 6].
Then replace the original array a new array bin which one element we have less. The next time you click all again and the array a will be one element less. Guys, it's very simple.
April 3rd 20 at 18:59
1) you creates an array a with elements 4, 5, 6
2) when you run the function creates an empty array b
3) a loop from 1 to the end of the array a (i.e., from the second to the last element of the array a)
4) but thanks [i-1] in the array b are written to the array elements and with a shift of 1 (i.e., b[0] = a[1], b[1] = a[2])

Find more questions by tags JavaScript