For the complete documentation index, see llms.txt. This page is also available as Markdown.

array

The primary array class in BoxLang.

This class wraps a Java List and provides additional functionality for BoxLang.

BoxLang indices are one-based, so the first element is at index 1, not 0.

Array Methods

append(value=[any], merge=[boolean])

Append a value to an array

Method Signature

append(value=[any], merge=[boolean])

Arguments

Argument
Type
Required
Description
Default

value

any

true

The element to append. Can be any type.

merge

boolean

false

If true, the value is assumed to be an array and the elements of the array are appended to the array. If false, the value is appended as a single element.

false

avg()

Return length of array

Method Signature

avg()

Arguments

This function does not accept any arguments

bxDump(label=[string], depth=[numeric], maxRows=[numeric], top=[numeric], expand=[boolean], abort=[boolean], output=[string], format=[string], showUDFs=[boolean])

Outputs the contents of a variable (simple or complex) of any type for debugging purposes to a specific output location.

The available output locations are: - buffer: The output is written to the buffer, which is the default location. If running on a web server, the output is written to the browser. - console: The output is printed to the System console. - Absolute File Path The output is written to a file with the specified absolute file path.

The output format can be either HTML or plain text.

The default format is HTML if the output location is the buffer or a web server or a file, otherwise it is plain text for the console.

Method Signature

bxDump(label=[string], depth=[numeric], maxRows=[numeric], top=[numeric], expand=[boolean], abort=[boolean], output=[string], format=[string], showUDFs=[boolean])

Arguments

Argument
Type
Required
Description
Default

label

string

false

A custom label to display above the dump (Only in HTML output)

depth

numeric

false

The recursion depth to display when dumping nested collections. 1-based: -1 (default) is unlimited, 0 shows nothing, 1 shows the top level with no recursion, 2 recurses once, etc. (Only in HTML output)

maxRows

numeric

false

The maximum number of keys/rows/items to display per level of a collection, array, or query. 1-based: -1 (default) is unlimited, 0 shows nothing, 1 shows a single row, etc. (Only in HTML output)

top

numeric

false

Deprecated: use maxRows instead. When maxRows is not also passed, top's value is used as maxRows. Kept for backwards compatibility with existing BoxLang code. (Only in HTML output)

expand

boolean

false

Whether to expand the dump. Be default, we try to expand as much as possible. (Only in HTML output)

true

abort

boolean

false

Whether to do a hard abort the request after dumping. Default is false

false

output

string

false

The output format which can be "buffer", "console", or "{absolute file path}". The default is "buffer".

format

string

false

The format of the output to a filename. Can be "html" or "text". The default is according to the output location.

showUDFs

boolean

false

Show UDFs or not. Default is true. (Only in HTML output)

true

chunk(length=[integer])

Chunks the array into an array of arrays of the specified size.

The final chunk may be shorter if the array does not divide evenly.

 numbers = [ 1, 2, 3, 4, 5 ];
 numbers.chunk( 2 ); // [ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]
 

Method Signature

chunk(length=[integer])

Arguments

Argument
Type
Required
Description
Default

length

integer

true

The size of each chunk.

clear()

Clear all items from array

Method Signature

Arguments

This function does not accept any arguments

contains(value=[any], substringMatch=[boolean])

This function searches the array for the specified value. Returns the index in the array of the first match, or 0 if there is no match.

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to find or a closure to be used as a search function.

substringMatch

boolean

false

If true, the search will be a substring match. Default is false. This only works on simple values, not complex ones. For that just use a function filter.

false

containsNoCase(value=[any], substringMatch=[boolean])

This function searches the array for the specified value. Returns the index in the array of the first match, or 0 if there is no match.

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to find or a closure to be used as a search function.

substringMatch

boolean

false

If true, the search will be a substring match. Default is false. This only works on simple values, not complex ones. For that just use a function filter.

false

delete(value=[any], scope=[string])

Delete first occurance of item in array case sensitive

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to deleted.

scope

string

false

Which matches to delete: "one" (default) deletes the first matching value, "all" deletes every matching value.

one

deleteAt(index=[integer])

Delete item at specified index in array

Method Signature

Arguments

Argument
Type
Required
Description
Default

index

integer

true

The index to deleted.

deleteNoCase(value=[any], scope=[string])

Delete first occurance of item in array case sensitive

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to deleted.

scope

string

false

Which matches to delete: "one" (default) deletes the first matching value, "all" deletes every matching value.

one

duplicate(deep=[boolean])

Duplicates an object - either shallow or deep

Method Signature

Arguments

Argument
Type
Required
Description
Default

deep

boolean

false

Whether to deep copy the object or make a shallow copy (e.g. only the top level keys in a struct)

true

each(callback=[function:Consumer], parallel=[boolean], maxThreads=[any], ordered=[boolean], virtual=[boolean])

Used to iterate over an array and run the function closure for each item in the array.

This BIF is used to perform an operation on each item in the array, similar to Java's forEach method. It can also be used to perform operations in parallel if the parallel argument is set to true.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the iterator will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the iterator in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Consumer

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Comparator which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

ordered

boolean

false

whether parallel operations should execute and maintain order

false

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

equals(obj=[any])

Verifies equality with the following rules:

  • Same object

  • Super class

Method Signature

Arguments

Argument
Type
Required
Description
Default

obj

any

true

every(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Used to iterate over an array and test whether every item meets the test callback.

The function will be passed 3 arguments: the value, the index, and the array. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise.

Note: This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that does not meet the test condition.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. This allows for efficient processing of large arrays, especially when the test function is computationally expensive or the array is large.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Predicate

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

filter(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Filters an array and returns a new array containing the result This BIF will invoke the callback function for each item in the array, passing the item, its index, and the array itself.

  • If the callback returns true, the item will be included in the new array.

  • If the callback returns false, the item will be excluded from the new array.

  • If the callback requires strict arguments, it will only receive the item and its index.

  • If the callback does not require strict arguments, it will receive the item, its index, and the array itself.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to filter, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Predicate

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

find(value=[any], substringMatch=[boolean])

This function searches the array for the specified value. Returns the index in the array of the first match, or 0 if there is no match.

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to find or a closure to be used as a search function.

substringMatch

boolean

false

If true, the search will be a substring match. Default is false. This only works on simple values, not complex ones. For that just use a function filter.

false

findAll(value=[any])

Return an array containing the indexes of matched values

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to found.

findAllNoCase(value=[any])

Return an array containing the indexes of matched values

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to found.

findFirst(callback=[function], defaultValue=[any], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Return first item in array that matches the predicate function.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

defaultValue

any

false

The default value to use if the array is empty or no value is returned from the predicate function.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

findNoCase(value=[any], substringMatch=[boolean])

This function searches the array for the specified value. Returns the index in the array of the first match, or 0 if there is no match.

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to find or a closure to be used as a search function.

substringMatch

boolean

false

If true, the search will be a substring match. Default is false. This only works on simple values, not complex ones. For that just use a function filter.

false

first(defaultValue=[any])

Return first item in array

Method Signature

Arguments

Argument
Type
Required
Description
Default

defaultValue

any

false

The value to return when the array is empty. If omitted, an exception is thrown for an empty array.

flatMap(callback=[function:Function], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Maps each element and flattens the result one level.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Function

true

The function to invoke for each item. The function will be passed 3 arguments: the current item, and the current index, and the original array. You can alternatively pass a Java Function which will only receive the 1st arg.

parallel

boolean

false

If true, the function will be invoked in parallel using multiple threads. Defaults to false.

false

maxThreads

any

false

The maximum number of threads to use when parallel is true. If not provided the common thread pool will be used. If a boolean value is passed, it will be assigned as the virtual argument.

virtual

boolean

false

If true, the function will be invoked using virtual thread. Defaults to false. Ignored if parallel is false.

false

flatten(depth=[integer])

Flattens nested arrays to the specified depth.

When depth is omitted, the array is flattened completely.

Method Signature

Arguments

Argument
Type
Required
Description
Default

depth

integer

false

The depth to flatten. If omitted, flatten all nested arrays.

getMetadata()

Gets metadata for items of an array and indicates the array type.

Method Signature

Arguments

This function does not accept any arguments

groupBy(callback=[function])

Returns a struct of keys returned from the predicate function and values of arrays of matching rows.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

hash(algorithm=[string], encoding=[string], numIterations=[integer])

Creates an algorithmic hash of an object

Method Signature

Arguments

Argument
Type
Required
Description
Default

algorithm

string

false

The supported java.security.MessageDigest algorithm (case-insensitive) or "quick" for an insecure 64-bit hash

MD5

encoding

string

false

Applicable to strings ( default "utf-8" )

utf-8

numIterations

integer

false

The number of iterations to re-digest the object ( default 1 );

1

indexExists(index=[any])

Returns whether there exists an item in the array at the selected index.

Method Signature

Arguments

Argument
Type
Required
Description
Default

index

any

true

The index to check.

insertAt(position=[integer], value=[any])

Append a value to an array

Method Signature

Arguments

Argument
Type
Required
Description
Default

position

integer

true

The position to insert at

value

any

true

The value to insert

isDefined(index=[any])

Returns whether there exists an item in the array at the selected index.

Method Signature

Arguments

Argument
Type
Required
Description
Default

index

any

true

The index to check.

isEmpty()

Determine whether a given value is empty.

We check for emptiness of anything that can be casted to: Array, Struct, Query, or String.

Method Signature

Arguments

This function does not accept any arguments

join(delimiter=[String], initialValue=[any])

Used to iterate over an array and run the function closure for each item in the array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

delimiter

String

false

The character to use as a separator

,

initialValue

any

false

last()

Return first item in array

Method Signature

Arguments

This function does not accept any arguments

len()

Returns the absolute value of a number

Method Signature

Arguments

This function does not accept any arguments

map(callback=[function:Function], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Iterates over every entry of the array and calls the closure function to work on the element of the array.

The returned value will be set at the same index in a new array and the new array will be returned

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Function

true

The function to invoke for each item. The function will be passed 3 arguments: the current item, and the current index, and the original array. You can alternatively pass a Java Function which will only receive the 1st arg. The function should return the value that will be set at the same index in the new array.

parallel

boolean

false

If true, the function will be invoked in parallel using multiple threads. Defaults to false.

false

maxThreads

any

false

The maximum number of threads to use when parallel is true. If not provided the common thread pool will be used. If a boolean value is passed, it will be assigned as the virtual argument.

virtual

boolean

false

If true, the function will be invoked using virtual thread. Defaults to false. Ingored if parallel is false.

false

max()

Get the max value from an array

Method Signature

Arguments

This function does not accept any arguments

median()

Return the median value of an array.

Will only work on arrays that contain only numeric values.

Method Signature

Arguments

This function does not accept any arguments

merge(array2=[array], leaveIndex=[boolean])

This function creates a new array with data from the two passed arrays.

To add all the data from one array into another without creating a new array see the built in function ArrayAppend(arr1, arr2, true).

Method Signature

Arguments

Argument
Type
Required
Description
Default

array2

array

true

The second array to merge

leaveIndex

boolean

true

Set to true maintain value indexes - if two values have the same index it will keep values from array1

false

mid(start=[integer], length=[integer])

Extracts a sub array from an existing array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

start

integer

true

The position to start the slice from. Negative values count from the end of the array.

1

length

integer

false

The number of elements to return. 0 (default) returns all elements from start to the end of the array.

0

min()

Return length of array

Method Signature

Arguments

This function does not accept any arguments

none(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Used to iterate over an array and test whether NONE item meets the test callback.

This is the opposite of ArraySome.

The function will be passed 3 arguments: the value, the index, and the array. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise.

Note: This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that does meet the test condition.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. This allows for efficient processing of large arrays, especially when the test function is computationally expensive or the array is large.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Predicate

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored.

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

parallelStream()

Returns a parallel stream of the array

Method Signature

Arguments

This function does not accept any arguments

pop(defaultValue=[any])

Remove last item in array and return it

Method Signature

Arguments

Argument
Type
Required
Description
Default

defaultValue

any

false

The value to return when the array is empty. If omitted, an exception is thrown for an empty array.

prepend(value=[any])

Append a value to the start an array

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The value to prepend

push(value=[any])

Adds an element or an object to the end of an array, then returns the size of the modified array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

value

any

true

The element to append. Can be any type.

range(to=[numeric])

Build an array out of a range of numbers or using our range syntax: {start}..{end} or using the from and to arguments

You can also build negative ranges

Method Signature

Arguments

Argument
Type
Required
Description
Default

to

numeric

false

The last index item, or defaults to the from value

reduce(callback=[function:BiFunction], initialValue=[any])

Run the provided udf over the array to reduce the values to a single output

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:BiFunction

true

The function to invoke for each item. The function will be passed 3 arguments: the accumulator, the current item, and the current index. You can alternatively pass a Java BiFunction which will only receive the first 2 args. The function should return the new accumulator value.

initialValue

any

false

The initial value of the accumulator

reduceRight(callback=[function:BiFunction], initialValue=[any])

This function iterates over every element of the array and calls the closure to work on that element.

It will reduce the array to a single value, from the right to the left, and return it.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:BiFunction

true

The function to invoke for each item. The function will be passed 3 arguments: the accumulator, the current item, and the current index. You can alternatively pass a Java BiFunction which will only receive the first 2 args. The function should return the new accumulator value.

initialValue

any

false

The initial value of the accumulator

reject(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Filters an array and returns a new array containing the result.

This is the inverse of ArrayFilter.

This BIF will invoke the callback function for each item in the array, passing the item, its index, and the array itself.

  • If the callback returns false, the item will be included in the new array.

  • If the callback returns true, the item will be excluded from the new array.

  • If the callback requires strict arguments, it will only receive the item and its index.

  • If the callback does not require strict arguments, it will receive the item, its index, and the array itself.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to filter, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Predicate

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

virtual

boolean

false

If true, the function will be invoked using virtual threads. Defaults to false. Ignored if parallel is false.

false

resize(size=[integer])

Resets an array to a specified minimum number of elements.

This can improve performance, if used to size an array to its expected maximum. For more than 500 elements, use arrayResize immediately after using the ArrayNew BIF.

Method Signature

Arguments

Argument
Type
Required
Description
Default

size

integer

true

The new minimum size of the array

reverse()

Returns an array with all of the elements reversed.

The value in [0] within the input array will then exist in [n] in the output array, where n is the amount of elements in the array minus one.

Method Signature

Arguments

This function does not accept any arguments

set(start=[any], end=[any], value=[any])

In a one-dimensional array, sets the elements in a specified index range to a value.

Useful for initializing an array after a call to arrayNew.

Method Signature

Arguments

Argument
Type
Required
Description
Default

start

any

true

The starting index

end

any

true

The ending index

value

any

true

The value to set

shift(defaultValue=[any])

Removes the first element from an array and returns the removed element.

This method changes the length of the array. If used on an empty array, an exception will be thrown.

Method Signature

Arguments

Argument
Type
Required
Description
Default

defaultValue

any

false

The value to return when the array is empty. If omitted, an exception is thrown for an empty array.

slice(start=[integer], length=[integer])

Extracts a sub array from an existing array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

start

integer

true

The position to start the slice from. Negative values count from the end of the array.

1

length

integer

false

The number of elements to return. 0 (default) returns all elements from start to the end of the array.

0

some(callback=[function:Predicate], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Used to iterate over an array and test whether ANY items meet the test callback.

The function will be passed 3 arguments: the value, the index, and the array. You can alternatively pass a Java Predicate which will only receive the 1st arg. The function should return true if the item meets the test, and false otherwise.

Note: This operation is a short-circuit operation, meaning it will stop iterating as soon as it finds the first item that meets the test condition.

Parallel Execution

If the parallel argument is set to true, and no max_threads are sent, the filter will be executed in parallel using a ForkJoinPool with parallel streams. If max_threads is specified, it will create a new ForkJoinPool with the specified number of threads to run the filter in parallel, and destroy it after the operation is complete. Please note that this may not be the most efficient way to iterate, as it will create a new ForkJoinPool for each invocation of the BIF. You may want to consider using a shared ForkJoinPool for better performance.

Method Signature

Arguments

Argument
Type
Required
Description
Default

callback

function:Predicate

true

The function to invoke for each item. The function will be passed 3 arguments: the value, the index, the array. You can alternatively pass a Java Predicate which will only receive the 1st arg.

parallel

boolean

false

Whether to run the filter in parallel. Defaults to false. If true, the filter will be run in parallel using a ForkJoinPool.

false

maxThreads

any

false

The maximum number of threads to use when running the filter in parallel. If not passed it will use the default number of threads for the ForkJoinPool. If parallel is false, this argument is ignored. If a boolean is provided it will be assigned to the virtual argument instead.

virtual

boolean

false

If true, the function will be invoked using virtual thread. Defaults to false. Ignored if parallel is false.

false

sort(sortType=[any], sortOrder=[string], localeSensitive=[boolean], callback=[function:Comparator])

Sorts array elements.

Method Signature

Arguments

Argument
Type
Required
Description
Default

sortType

any

false

Options are text, numeric, or textnocase

textnocase

sortOrder

string

false

Options are asc or desc

asc

localeSensitive

boolean

false

Sort based on local rules

false

callback

function:Comparator

false

Function to sort by

splice(index=[Integer], elementCountForRemoval=[Integer], replacements=[array])

Modifies an array by removing elements and adding new elements.

It starts from the index, removes as many elements as specified by elementCountForRemoval, and puts the replacements starting from index position.

Method Signature

Arguments

Argument
Type
Required
Description
Default

index

Integer

true

The initial position to remove or insert from

elementCountForRemoval

Integer

false

The number of elemetns to remove

0

replacements

array

false

An array of elements to insert

stream()

Returns a stream of the array

Method Signature

Arguments

This function does not accept any arguments

sum()

Returns the sum of all values in an array

Method Signature

Arguments

This function does not accept any arguments

swap(position1=[any], position2=[any])

Swaps array values of an array at specified positions.

This function is more efficient than multiple assignment statements

Method Signature

Arguments

Argument
Type
Required
Description
Default

position1

any

true

The first position to swap

position2

any

true

The second position to swap

toJSON(queryFormat=[string], useSecureJSONPrefix=[string], useCustomSerializer=[boolean], pretty=[boolean])

Converts a BoxLang variable into a JSON (JavaScript Object Notation) string according to the specified options.

Query Format Options

The queryFormat argument determines how queries are serialized:

  • row or false: Serializes the query as a top-level struct with two keys: columns (an array of column names) and data (an array of arrays representing each row's data).

  • column or true: Serializes the query as a top-level struct with three keys: rowCount (the number of rows), columns (an array of column names), and data (a struct where each key is a column name and the value is an array of values for that column).

  • struct: Serializes the query as an array of structs, where each struct represents a row of data.

Usage

Method Signature

Arguments

Argument
Type
Required
Description
Default

queryFormat

string

false

If the variable is a query, specifies whether to serialize the query by rows or by columns. Valid values are: row same as false, column same as true, or struct. Defaults to row.

useSecureJSONPrefix

string

false

If true, the JSON string is prefixed with a secure JSON prefix. (Not implemented yet)

false

useCustomSerializer

boolean

false

If true, the JSON string is serialized using a custom serializer. (Not implemented yet)

pretty

boolean

false

If true, the JSON string is formatted with indentation and line breaks for readability. Defaults to false.

false

toList(delimiter=[String], initialValue=[any])

Used to iterate over an array and run the function closure for each item in the array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

delimiter

String

false

The character to use as a separator

,

initialValue

any

false

toModifiable()

Convert an array, struct, query or set to its Modifiable counterpart.

Method Signature

Arguments

This function does not accept any arguments

toSet(type=[string], delimiter=[string])

Convert a collection into a Set, deduplicating automatically.

Accepts an Array, a list-delimited String, an existing Set, a QueryColumn, an XML node, a bounded Range, or any value castable to a Set. When the value is already of the requested variant it is returned as-is; otherwise a new Set of the specified variant is created and populated.

Method Signature

Arguments

Argument
Type
Required
Description
Default

type

string

false

The backing variant: "default" / "hash" (HashSet), "linked" / "ordered" (LinkedHashSet), or "sorted" / "tree" (TreeSet). When omitted, the caster defaults to LINKED for ordered collections like Arrays.

delimiter

string

false

When value is a String, the list delimiter to split on. Defaults to ",".

,

toStruct()

Transform the array to a struct, the index of the array is the key of the struct

Method Signature

Arguments

This function does not accept any arguments

toUnmodifiable()

Convert an array, struct, query or set to its Unmodifiable counterpart.

Method Signature

Arguments

This function does not accept any arguments

transpose()

Returns a transposed array based on all passed in arrays.

Method Signature

Arguments

This function does not accept any arguments

unique(caseSensitive=[boolean])

Returns a new array with duplicate items removed.

Method Signature

Arguments

Argument
Type
Required
Description
Default

caseSensitive

boolean

false

Whether string element comparisons are case-sensitive. Defaults to false.

false

unshift(object=[any])

This function adds one or more elements to the beginning of the original array and returns the length of the modified array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

object

any

true

The value to add

zip(array2=[array], callback=[function], parallel=[boolean], maxThreads=[any], virtual=[boolean])

Returns a zipped array.

Method Signature

Arguments

Argument
Type
Required
Description
Default

array2

array

true

The second array to zip

callback

function

false

An optional callback function to receive the item and the current index from both zipped arrays and return a new value.

parallel

boolean

false

If true, the function will be invoked in parallel using multiple threads. Defaults to false.

false

maxThreads

any

false

The maximum number of threads to use when parallel is true. If not provided the common thread pool will be used. If a boolean value is passed, it will be assigned as the virtual argument.

virtual

boolean

false

If true, the function will be invoked using virtual thread. Defaults to false. Ignored if parallel is false.

false

Last updated

Was this helpful?