Removes the first element from an array and returns that element. This method changes the length of the array.
Array
shift()
The following code displays the myFish array before and after removing its first element. It also displays the removed element:
myFish = ["angel", "clown", "mandarin", "surgeon"]; Console.Write("myFish before: " + myFish); shifted = myFish.shift(); Console.Write("myFish after: " + myFish); Console.Write("Removed this element: " + shifted);
This example displays the following:
myFish before: ["angel", "clown", "mandarin", "surgeon"] myFish after: ["clown", "mandarin", "surgeon"] Removed this element: angel
Array: pop, Array: push, Array: unshift