I want the array to switch places between the last one and the first. that the output will be 8-1 but when I try to do that the first index is undefined and the second is still 1
var arr1 = [1, 2, 3, 4, 5, 6, 7, 8];
for (var i = 0; i <= arr1.length / 2; i++) {
var tmp = arr1[i];
arr1[i] = arr1[arr1.length - i];
arr1[arr1.length - i] = tmp;
};
console.log(arr1);
does anyone can help me to understand why?