124
rated 0 times
[
127]
[
3]
/ answers: 1 / hits: 26480
/ 11 Years ago, fri, april 19, 2013, 12:00:00
I have this array:
var arr1 = ['a1', 'a2', 'a3', 'a4', 'a5'];
I need to shift it to right by say 2 locations, like
arr1 = ['a4', 'a5', 'a1', 'a2', 'a3'];
This works for left shift:
arr1 = arr1.concat(arr1.splice(0,2)); // shift left by 2
I get :
arr1 = ['a3', 'a4', 'a5', 'a1', 'a2'];
But I don't know how to do shift right...
More From » javascript