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

Arguments:

avg()

Return length of array

clear()

Clear all items from array

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

Array finders and contains functions with and without case sensitivity.

Please note that "contain" methods return a boolean, while "find" methods return an index. If you use a function as the value, it will be used as a search closure or lambda. The signature of the function should be:

,

,
( value, index ) => {
return true; // if the value is found, else false
}
,

,

Example:

,

,
array = [ 1, 2, 3, 4, 5 ];
index = array.find( ( value, index ) -> {
return value == 3;
} );
,

,

We recommend you use BoxLang lambdas (,{@code ->},) for this purpose, so they only act upon the value and index without any side effects. They will be faster and more efficient.

Arguments:

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

Array finders and contains functions with and without case sensitivity.

Please note that "contain" methods return a boolean, while "find" methods return an index. If you use a function as the value, it will be used as a search closure or lambda. The signature of the function should be:

,

,
( value, index ) => {
return true; // if the value is found, else false
}
,

,

Example:

,

,
array = [ 1, 2, 3, 4, 5 ];
index = array.find( ( value, index ) -> {
return value == 3;
} );
,

,

We recommend you use BoxLang lambdas (,{@code ->},) for this purpose, so they only act upon the value and index without any side effects. They will be faster and more efficient.

Arguments:

copyOf(arr=[any])

Create a new Array from a list of values.

Arguments:

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

Delete first occurance of item in array case sensitive

Arguments:

deleteAt(index=[integer])

Delete item at specified index in array

Arguments:

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

Delete first occurance of item in array case sensitive

Arguments:

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

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

Arguments:

equals(obj=[any])

Verifies equality with the following rules:

  • Same object

  • Super class

Arguments:

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

Returns true if every closure returns true, otherwise false

Arguments:

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

Used to filter an array to items for which the closure function returns true.

Arguments:

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.

Arguments:

findAll(value=[any])

Return an array containing the indexes of matched values

Arguments:

findAllNoCase(value=[any])

Return an array containing the indexes of matched values

Arguments:

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

Array finders and contains functions with and without case sensitivity.

Please note that "contain" methods return a boolean, while "find" methods return an index. If you use a function as the value, it will be used as a search closure or lambda. The signature of the function should be:

,

,
( value, index ) => {
return true; // if the value is found, else false
}
,

,

Example:

,

,
array = [ 1, 2, 3, 4, 5 ];
index = array.find( ( value, index ) -> {
return value == 3;
} );
,

,

We recommend you use BoxLang lambdas (,{@code ->},) for this purpose, so they only act upon the value and index without any side effects. They will be faster and more efficient.

Arguments:

first()

Return first item in array

getMetadata()

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

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

Creates an algorithmic hash of an object

Arguments:

indexExists(index=[any])

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

Arguments:

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

Append a value to an array

Arguments:

isDefined(index=[any])

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

Arguments:

isEmpty()

Determine whether a given value is empty.

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

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

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

Arguments:

last()

Return first item in array

len()

Returns the absolute value of a number

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

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

Arguments:

max()

Get the max value from an array

median()

Return the median value of an array.

Will only work on arrays that contain only numeric values.

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).

Arguments:

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

Extracts a sub array from an existing array.

Arguments:

min()

Return length of array

of(values=[any])

Create an Array from a list of values.

Each value is passed in as a separate argument

Arguments:

parallelStream()

Returns a parallel stream of the array

pop(defaultValue=[any])

Remove last item in array and return it

Arguments:

prepend(value=[any])

Append a value to the start an array

Arguments:

push(value=[any])

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

Arguments:

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 ,

,

,

,
arrayRange( "1..5" )
arrayRange( "-10..5" )
arrayRange( 1, 500 )
,

Arguments:

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

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

Arguments:

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.

Arguments:

resize(size=[any])

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.

Arguments:

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.

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.

Arguments:

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.

Arguments:

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

Extracts a sub array from an existing array.

Arguments:

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

Calls a given closure/function with every element in a given array and returns true if one of the closure calls returns true

Arguments:

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

Sorts array elements.

Arguments:

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.

Arguments:

stream()

Returns a stream of the array

sum()

Returns the sum of all values in an array

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

Swaps array values of an array at specified positions.

This function is more efficient than multiple assignment statements

Arguments:

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

Converts a BoxLang variable into a JSON (JavaScript Object Notation) string.

Arguments:

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

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

Arguments:

toModifiable()

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

toStruct()

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

toUnmodifiable()

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

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.

Arguments:

Examples

Last updated

Logo

Copyright & Register Trademark by Ortus Solutions, Corp & Ortus Software, LLC