ValueArray

Description

This function converts the values of a specified column of a query into an array.

Returns

An array of column values.

Category

History

New In Adobe ColdFusion (2016 release)

Syntax

ValueArray (Object query, String columnName)

Parameters

Parameter

Req/Opt

Description

query

Required

The query to be iterated over.

columnName

Required

The name of the column whose values you want to return.

Example 1

<cfscript>
    myQuery = queryNew("id,name,amount","Integer,Varchar,Integer", 
                [ 
                        {id=1,name="One",amount=15}, 
                        {id=2,name="Two",amount=18}, 
                        {id=3,name="Three",amount=32},
                        {id=4,name="Four",amount=53}
                ]);
   // Convert the values in the column Address into the array myColumn
    arrayList=ValueArray(myQuery,"name")
    
   // Display array values
   writeDump(arrayList)
</cfscript>

Output

Example 2

<cfscript>
       // Execute a query from table Orders
       myQuery=QueryExecute("select * from orders",[],{datasource="cfartgallery"});
       // Convert the values in the column Address into the array myColumn
       myColumn=ValueArray(myQuery,"Address");
       // Display array values
       writedump(myColumn);
</cfscript>

Output

Note:

Before the implementation of ValueArrray member function, you could also use query["column"] to convert the column values into an array, as shown below:

<cfscript>
  a=[];
  q = queryNew("foobar", "", [["foo"],["bar"]]);
  a.append(q["foobar"], true);
  writeDump(a);//returns same result as q.valueArray("foobar")
</cfscript>

Get help faster and easier

New user?