5.反转数组
var arr = [1,2,3,4,5,6,7,8]; for(let i = 0;i<arr.length/2;i++){ //arr[0] arr[arr.length-1-0]; //arr[1] arr[arr.length-1-1]; //arr[2] arr[arr.length-1-2]; //arr[3] arr[arr.length-1-3]; //借助第三方变量交换两个变量的值 //var temp = arr[i]; //arr[i] = arr[arr.length-1-i]; //arr[arr.length-1-i] = temp; [arr[i],arr[arr.length-1-i]]=[arr[arr.length-1-i],arr[i]] } console.log(arr);