array.pop()

pops the last element from an array. In case the array is empty an exception is thrown, unless the second argument "defaultValue" is provided, in that case that value is returned.

Introduced: 5.3.8.104

array.pop( defaultValue=any )

Returns: any

Argument Description
defaultValue
any, optional

this value is returned in case the array is empty

Examples

Arraypop member examples

numbers = [ 1, 2, 3, 4 ];
	dump( numbers.pop( 0 ) ); // Outputs 4
	dump( numbers ); // Outputs [ 1, 2, 3 ]
<span class="nv">moreNumbers</span> <span class="o">=</span> <span class="p">[</span> <span class="m">5</span><span class="p">,</span> <span class="m">6</span><span class="p">,</span> <span class="m">7</span><span class="p">,</span> <span class="m">8</span> <span class="p">];</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nf">moreNumbers.pop</span><span class="p">(</span> <span class="m">4</span> <span class="p">)</span> <span class="p">);</span> <span class="c">// Outputs 8</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nv">moreNumbers</span> <span class="p">);</span> <span class="c">// outputs [ 5, 6, 7 ]</span>
<span class="nv">moreNumbers</span> <span class="o">=</span> <span class="p">[</span>  <span class="p">];</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nf">moreNumbers.pop</span><span class="p">(</span> <span class="m">4</span> <span class="p">)</span> <span class="p">);</span> <span class="c">// Outputs 4 (default)</span>
<span class="nf">dump</span><span class="p">(</span> <span class="nv">moreNumbers</span> <span class="p">);</span> <span class="c">// Outputs [  ];</span>

See also