使用es6使数组的第一项和最后一项就行调换
let arr = [1, 2, 3,4]; let a = arr.filter((item, index) => { return index > 0 && index < (arr.length - 1) }); let arr2 = [arr[arr.length-1],...a,arr[0]]; console.log(arr2)
let arr = [1, 2, 3,4]; let a = arr.filter((item, index) => { return index > 0 && index < (arr.length - 1) }); let arr2 = [arr[arr.length-1],...a,arr[0]]; console.log(arr2)