Creates an array of 1-3 dimensions. Index array elements with square brackets: [ ]. CFML arrays expand dynamically as data is added.
arrayNew(dimension [, isSynchronized])
→ returns array
1
1
2
3
true
Uses the arrayNew function to create the new array
newArray = arrayNew(1);
someArray = arraySet(newArray, 1, 4, "All is well");
writeOutput( serializeJSON(newArray) );
Expected Result: ["All is well", "All is well", "All is well", "All is well"]
Uses the arrayNew function to create the new array
newArray = arrayNew(2);
newArray[1][1] = "First value";
newArray[1][1] = "First value";
newArray[1][2] = "First value";
newArray[2][1] = "Second value";
newArray[2][2] = "Second value";
writeOutput( serializeJSON(newArray) );
Expected Result: [["First value", "First value"],["Second value", "Second value"]]
CF 2016+ Uses the arrayNew function to create the new unsynchronized array
newArray = arrayNew(1, false);
newArray.append("one");
writeOutput( serializeJSON(newArray) );
Expected Result: ["one"]
CF 8+ Instead of using arrayNew you can also create an array using square brackets.
newArray = ["one","two"];
writeOutput( serializeJSON(newArray) );
Expected Result: ["one", "two"]
CF 2018+ When using data types on array creation, items are converted if possible, otherwise an error is thrown.
typedArray = arrayNew['boolean'](1);
typedArray[1] = true;
typedArray[2] = 'true';
typedArray[3] = 1;
typedArray[4] = '1';
typedArray[5] = 'yes';
typelessArray = arrayNew(1);
typelessArray[1] = true;
typelessArray[2] = 'true';
typelessArray[3] = 1;
typelessArray[4] = '1';
typelessArray[5] = 'yes';
writeOutput(serializeJSON([typedArray,typelessArray]));
Expected Result: [[true,true,true,true,null,true],[true,"true",1,"1",null,"yes"]]
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.