JavaScript Array pop()

The pop() method removes the last element from an array and returns that element.

Example


pop() Syntax

The syntax of the pop() method is:

arr.pop()

Here, arr is an array.


pop() Parameters

The pop() method does not have any parameters.


pop() Return Value

  • Removes the last element from array and returns that value.
  • Returns undefined if the array is empty.

Notes:

  • This method changes the original array and its length.
  • To remove the first element of an array, use the JavaScript Array shift() method.

Example: Using pop() method

Output

[ 'JavaScript', 'Python', 'Java', 'C++' ]
Lua
[ -5, -4, -3 ]
[ [ 1, 2, 3 ], [ 4, 5, 6 ] ]

Recommended Readings: