POP
NAME
pop - Removes the last element from array and returns it.
SYNOPSIS
pop(array)
pop(array, elem1_position, ...)
DESCRIPTION
This function removes the last element of an array. and returns it.
So if a = [1,2,3,4,5]; pop(a) return 5 and a has value 1,2,3,4.
In the second form, pop remove the element based on the position starting at zero.
If the value of elem1_position is less than zero, it will remove the element based on the position from the end starting at 1.
The second form is available from version 5.89
PARAMETERS
array : required, the array to remove element from.
elem1_position: optional, index/position of the element to remove.
elem2_position: optional, index/position of the element to remove. Can be negative number which indicates the position of removing will start from the end at 1.
RETURN
Returns the last element of an array.
EXAMPLES
a = [1,2,3,4,5];
a.top();
a.last();
a.shift();
a;
a.pop();
a;
will return es=151[2,3,4,5]5[2,3,4].
a = [1,2,3,4,5];
a.pop(-2,-4);
a;
return res=[4,2][1,3,5].
a = [1,2,3,4,5];
a.pop(-2,-100);
a;
return array is size 5 and you try to remove element -100
a = [1,2,3,4,5];
a.pop(2,3);// returns [3,4], popped elements
a;// returns new array after removal. elements at index 2 and 3 are removed.
return res=[3,4][1,2,5].
a = [1,2,3,4,5];
a.pop(0,1, 2,3);
a;
return res=[1,2,3,4][5].
a = [1,2,3,4,5];
a.pop(0,1, 2,3,4);
a;
return res=[1,2,3,4,5][].
a = [1,2,3,4,5];
a.pop(0,1, 2,3,4,5);
a;
return array is size 5 and you try to remove element 5
a = [1,2,3,4,5];
a.pop(2,3, 10);
a;
return array is size 5 and you try to remove element 10
a = [1,2,3,4,5];
a.pop(2,3, -10);
a;
return array is size 5 and you try to remove element -10
SEE ALSO
{{ include("includes/array.sn") }}
AUTHOR
Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>
MODIFICATIONS
1.0 2014-09-09 21:24:14 laplante@sednove.com
2.0 2017-08-03 laplante@sednove.com The second form is working fromn version 5.89
Edit