Shifting an array with less touches I have an array that I am shifting by a certain number of spaces.  I am wondering if there is an better way to do the shift with less touches.  Here is my code

function rotate_array(array, shift){

    if(array.length -1 &lt;= shift){
        shift %= array.length;
    }
    for(var i =0; i &lt; shift; i++){
        var first = array[0];
        for(var j =0; j &lt; array.length -1 ;j++){
            array[j] = array[j+1]
        }
        array[array.length - 1]  = first
    }
}

 var array = [4,2,1,3,5];
 rotate_array(array, 22);

  for(var i =0; i &lt; array.length; i++){
    console.log(array[i])
 };
You can just use concat and splice..

shift %= array.length;
array = array.concat(array.splice(0,shift));


Or if you want the same array referance you can shift and push

for(i = 0; i &lt; shift; i ++){
   var item = array.shift();
   array.push(item);
}


or shorten to 

while((shift--) &gt; 0){
   array.push(array.shift());
}