Javascript Array Question 27

Introduction

Shift Array Values

Given an array, shift all values forward, dropping the first value and leaving an extra '0' value at the end.


function shift_array(arr) {
  //your code
  return arr;
}
shift_array([1,2,3,4]);




function shift_array(arr) {
  for (var i = 1; i < arr.length; i++) {
    arr[i-1] = arr[i];
  }
  arr[arr.length-1] = 0;
  return arr;
}
shift_array([1,2,3,4]);



PreviousNext

Related