ArrayPush

Description

Adds an element or an object to the end of an array.

Returns

The new size of the array.

Syntax

ArrayPush(array, value)

Member function

array.push(value)

History

New in ColdFusion (2021 release)

Parameters

Parameter

Required/Optional

Description

array

Required

Array to which a value or object is to be added.

value

Required

The value or object to be added to the array.

Examples

Example 1

<cfscript> 
    arr=[23,65,187,81,9] 
    ArrayPush(array=arr,value=17) 
    WriteOutput("The size of the array is now: " & arrayLen(arr)) 
</cfscript>

Output

The size of the array is now: 6

Example 2

<cfscript> 
    arr=[1,3,5,7,9] 
    ArrayPush(arr,[11,13]) // using an array as value 
    WriteOutput("The size of the array is now: " & arrayLen(arr)) 
</cfscript>

Output

The size of the array is now: 6

Example 3

<cfscript> 
    arr=[{"id":101,"name":"John"}, 
         {"id":102,"name":"Paul"}, 
         {"id":103,"name":"George"} 
        ] 
    ArrayPush(arr,{"id":104,"name":"Ringo"}) 
    WriteOutput("The size of the array is now: " & arrayLen(arr)) 
</cfscript>

Output

The size of the array is now: 6

Example 4

<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"} 
    ]); 
 ArrayPush(arrOfQ,Q3) 
 WriteOutput("The size of the array is now: " & arrayLen(arrOfQ)) 
</cfscript>

Output

The size of the array is now: 3

 Adobe

Få hjälp snabbare och enklare

Ny användare?

Adobe MAX 2024

Adobe MAX

The Creativity Conference

14–16 oktober i Miami Beach och online

Adobe MAX 2024

Adobe MAX

The Creativity Conference

14–16 oktober i Miami Beach och online