Javascript - Array pop() Method

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

Description

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

This method changes the length of an array.

To remove the first element of an array, use the shift() method.

pop() method is using the array as stack.

Syntax

array.pop()

Parameters

None

Return

Any type, representing the removed array item.

The array item can be a string, a number, an array, a boolean, or any other object types stored in an array.

Example

Remove the last element of an array:

Demo

var myArray = ["XML", "Json", "Database", "Mango"];
console.log( myArray);/*from w w  w. j a v a  2  s  . co  m*/

var r = myArray.pop();
console.log( myArray );
console.log( r );

Result