I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.
A good way to understand what a piece of code does it’s to visualise the output. A simple way to do this is to print the result of each iteration to the console, a more advanced way to do this is using a debugger tool - such as the tool included with visual studio code
for (let i = arr.length; i >= 0; i--) {
// i == number of items in []
// start counting from i
// do something while i >= 0
// let i = i - 1 after each loop
arr[i] = arr[i - 1];
// to index i of arr, assign whatever is at index i - 1
for (let i = 1; i < arr.length; i++) {
arr[i - 1] = arr[i];