Parameter
Laatst bijgewerkt op
3 mei 2021
Description
Removes the last element from an array.
Returns
The popped element.
Syntax
ArrayPop(array)
ArrayPop(array)
ArrayPop(array)
Member function
array.pop()
array.pop()
array.pop()
History
New in ColdFusion (2021 release)
Parameters
|
Required/Optional |
Description |
---|---|---|
array |
Required |
The array whose last element is to be removed. |
Opmerking:
If you apply ArrayPop to an empty array, there is an exception.
Example
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
]
// Array push
ArrayPush(arr,{"id":104,"name":"Ringo"})
// Array pop
WriteDump(ArrayPop(arr))
</cfscript>
<cfscript>
arr=[{"id":101,"name":"John"},
{"id":102,"name":"Paul"},
{"id":103,"name":"George"}
]
// Array push
ArrayPush(arr,{"id":104,"name":"Ringo"})
// Array pop
WriteDump(ArrayPop(arr))
</cfscript>
<cfscript> arr=[{"id":101,"name":"John"}, {"id":102,"name":"Paul"}, {"id":103,"name":"George"} ] // Array push ArrayPush(arr,{"id":104,"name":"Ringo"}) // Array pop WriteDump(ArrayPop(arr)) </cfscript>
Output
Example
<cfscript>
Q1=queryNew(data=[
{"id":1,"title":"Moby Dick"},
{"id":2,"title":"Great Expectations"}
]);
Q2=queryNew(data=[
{"id":3,"title":"Hamlet"},
{"id":4,"title":"Macbeth"}
]);
arrOfQ=[Q1,Q2]
Q3=queryNew(data=[
{"id":5,"title":"Frankenstein"},
{"id":6,"title":"Metamorphosis"}
]);
// Array push
ArrayPush(arrOfQ,Q3)
// Array pop
WriteDump(ArrayPop(arrOfQ))
</cfscript>
<cfscript>
Q1=queryNew(data=[
{"id":1,"title":"Moby Dick"},
{"id":2,"title":"Great Expectations"}
]);
Q2=queryNew(data=[
{"id":3,"title":"Hamlet"},
{"id":4,"title":"Macbeth"}
]);
arrOfQ=[Q1,Q2]
Q3=queryNew(data=[
{"id":5,"title":"Frankenstein"},
{"id":6,"title":"Metamorphosis"}
]);
// Array push
ArrayPush(arrOfQ,Q3)
// Array pop
WriteDump(ArrayPop(arrOfQ))
</cfscript>
<cfscript> Q1=queryNew(data=[ {"id":1,"title":"Moby Dick"}, {"id":2,"title":"Great Expectations"} ]); Q2=queryNew(data=[ {"id":3,"title":"Hamlet"}, {"id":4,"title":"Macbeth"} ]); arrOfQ=[Q1,Q2] Q3=queryNew(data=[ {"id":5,"title":"Frankenstein"}, {"id":6,"title":"Metamorphosis"} ]); // Array push ArrayPush(arrOfQ,Q3) // Array pop WriteDump(ArrayPop(arrOfQ)) </cfscript>
Output