ColdFusion 2018 includes a host of new enhancements on Language. Language improvements have been considered based on use-cases that make more sense in today’s world, and while also taking into consideration all the bugs and enhancements logged by the community.
ColdFusion also includes enhancements on purely language constructs as well. We will be looking at Arrays and Strings here.
Datatypes can now be defined for Arrays. Supported Datatypes are String, Numeric, Boolean, Date, Array, Struct, Query, Components, Binary and Function. The scope of typed arrays can be extended by defining the type as a custom component as well. The syntax for typed array’s is defined below,
arr = arrayNew['String'](1);
Array’s can now be queried not just with indexes, but also with negative indexes. A negative index, -1, would fetch the last element of the array, a index of -2, would fetch the last but one element of the array, and so on and so forth. Syntax for negative indices is the same as that for querying array’s with indices.
Array’s can also be queried with the new slices syntax. The syntax allows you to specify the start index, end index, and a step. The step refers to the interval at which items in the array will be returned. For example, for the syntax displayed below, all alternate items in the array starting with the index 1, upto the last but one element will be returned. Alternate, since the step is specified as 2.
With String literals, you can now invoke string member function on the literals itself. This could be useful for authoring unit-tests, for example. Strings do not need to be stored in a variable before manipulations.
" The quick brown fox jumps over the lazy dog ".trim().len()
For more information on Array’s and String’s refer to the post on the ColdFusion Community Portal.