JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Array Right Arrow pop()

pop()  Array  instance method

Description

Syntax


Signature Description
anArray.pop()Removes the last element of an array and returns that elements value to the caller.

Parameters

None.

Examples

The code below creates an array then removes the last element.


/*
 Create an array of days of the week.
 Pop the last element.
 Variable lastDayOfWeek = 'Sun'.
 */
 var week = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun'];
var lastDayOfWeek = week.pop();
alert(lastDayOfWeek + ' - ' + week);

Press the button below to action the above code:

Related Tutorials

JavaScript Intermediate Tutorials - Lesson 1 - Arrays



  

go to home page Homepage go to top of page Top