Method 1: reverse method
There ArR 1 = [ 'a', 'b', 'c', 'd', 'e' ] console.log('source arr1 =', arr1) arr1.reverse() console.log('target arr1 =', arr1)
Mode 2: switching element position
was arr = [1, 2, 3, 4, 5, 6 ] console.log('source arr =', arr) for (var i = 0; i < arr.length / 2; i++) { var temp = arr[i] arr[i] = arr[arr.length - 1 - i] arr[arr.length - 1 - i] = temp } console.log('target arr =', arr)
reference:
https://github.com/wangjianuo/blog/issues/1