Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript pop() method

JavaScript pop() method

Array Object Reference JavaScript Array object

Example

Remove the last array element:

var

fruits

=

[

"

Banana

"

,

"

Orange

"

,

"

Apple

"

,

"

Mango

"

]

;

fruits

.

pop

(

)

;

fruits Result output:

Banana,Orange,Apple

Try it »


Definition and Usage

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

**Note:** This method changes the length of the array!

Tip: To remove the first array element, use shift() method.


Browser support

The numbers in the table indicate the first browser version that supports this method.

Method
pop() 1.0 5.5 1.0 Yes Yes

Syntax

array

.pop()

Return Value

Type Description
All types Returns the removed element.

Array elements may be a string, number, array, boolean, or other object type.

Technical Details

JavaScript version: 1.2

More examples

Example

const

sites

=

[

'

Google

'

,

'

Runoob

'

,

'

Taobao

'

,

'

Zhihu

'

,

'

Baidu

'

]

;

console

.

log

(

sites

.

pop

(

)

)

;

//

Output: "Baidu"

console

.

log

(

sites

)

;

//

Output: ['Google', 'Runoob', 'Taobao', 'Zhihu']

sites

.

pop

(

)

;

console

.

log

(

sites

)

;

//

Output: ["Google", "Runoob", "Taobao"]


Array Object Reference JavaScript Array object