Using .concat() , you create a new array and replace the old one. The problem is that if you have other array references, they will not be updated, so they will still save the unmoved version.
To make the right shift and actually modify the existing array, you can do this:
arr1.unshift.apply(arr1, arr1.splice(3,2));
The unshift() method is variable, and .apply allows .apply to pass multiple arguments stored in a collection similar to an array.
So .splice() mutates the array, deleting the last two and returning them, and .unshift() mutates the array, adding those that return .splice() to the beginning.
The left shift will be rewritten similarly to the right shift, since .push() also variable:
arr1.push.apply(arr1, arr1.splice(0,2));
user1106925
source share