pop

Removes the last element from an array and returns that element. This method changes the length of the array.

Applies to

Array

Syntax

pop()

Parameters

None

Example

The following code displays the myFish array before and after removing its last element. It also displays the removed element:

myFish = ["angel", "clown", "mandarin", "surgeon"];
Console.Write("\r\nmyFish before: " + myFish);
popped = myFish.pop();
Console.Write("\r\nmyFish after: " + myFish);
Console.Write("\r\npopped this element: " + popped);

This example displays the following:

myFish before: ["angel", "clown", "mandarin", "surgeon"]
myFish after: ["angel", "clown", "mandarin"]
popped this element: surgeon

See also

Array: push, Array: shift, Array: unshift