How to explain reversing an array in JavaScript using for loops
Solution 1:
You can use much simpler like:
const arr = [1, 2, 3, 4, 5]
const reversedArr = []
for (let i = arr.length - 1; i >= 0; i--) {
reversedArr.push(arr[i])
}
console.log(reversedArr)
Explanation is just, iterating over each item in the original array, but starting from the last item (arr.length = 5 here) and push each of them to a new array.