Parameter
This method adds one or more elements to the beginning of an array and returns the new length of the array.
The new size of the array.
ArrayUnshift(array,object)
Member function
array.unshift(item)
ColdFusion (2021 release): Added this function.
|
Parameter |
Required/Optional |
Description |
|---|---|---|
|
array |
Required |
The array where an object is to be added. |
|
object |
Required |
The object to add at the beginning of the array. |
Example 1
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
unshifted=ArrayUnshift(arr,"Jan")
WriteOutput(unshifted) // Returns 6
</cfscript>
Example 2
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
// List as first element
unshifted=ArrayUnshift(arr,"Jan,Feb") // Returns 6
WriteOutput(unshifted)
</cfscript>
Example 3
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
// Array as first element
unshifted=ArrayUnshift(arr,["Jan,Feb"])
WriteOutput(unshifted) // Returns 6
</cfscript>
Example 4
<cfscript>
arr=["Mar","Apr","May","Jun","Jul"]
// Struct as first element
elem={"id":101,"name":"John"}
unshifted=ArrayUnshift(arr,elem)
WriteOutput(unshifted) // Returns 6
</cfscript>
Sign in to your account