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:
value
any
true
null
merge
boolean
false
false
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:
value
any
true
null
substringMatch
boolean
false
false
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:
value
any
true
null
substringMatch
boolean
false
false
delete(value=[any], scope=[string])
Delete first occurance of item in array case sensitive
Arguments:
value
any
true
null
scope
string
false
one
deleteAt(index=[integer])
Delete item at specified index in array
Arguments:
index
integer
true
null
deleteNoCase(value=[any], scope=[string])
Delete first occurance of item in array case sensitive
Arguments:
value
any
true
null
scope
string
false
one
duplicate(deep=[boolean])
Duplicates an object - either shallow or deep
Arguments:
deep
boolean
false
true
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:
callback
function:Consumer
true
null
parallel
boolean
false
false
maxThreads
integer
false
null
ordered
boolean
false
false
initialValue
any
false
null
equals(obj=[any])
Verifies equality with the following rules:
Same object
Super class
Arguments:
obj
any
true
null
every(callback=[function:Predicate], parallel=[boolean], maxThreads=[integer], initialValue=[any])
Returns true if every closure returns true, otherwise false
Arguments:
callback
function:Predicate
true
null
parallel
boolean
false
false
maxThreads
integer
false
null
initialValue
any
false
null
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:
callback
function:Predicate
true
null
parallel
boolean
false
false
maxThreads
integer
false
null
initialValue
any
false
null
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:
value
any
true
null
substringMatch
boolean
false
false
findAll(value=[any])
Return an array containing the indexes of matched values
Arguments:
value
any
true
null
findAllNoCase(value=[any])
Return an array containing the indexes of matched values
Arguments:
value
any
true
null
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:
value
any
true
null
substringMatch
boolean
false
false
hash(algorithm=[string], encoding=[string], numIterations=[integer])
Creates an algorithmic hash of an object
Arguments:
algorithm
string
false
MD5
encoding
string
false
utf-8
numIterations
integer
false
1
indexExists(index=[any])
Returns whether there exists an item in the array at the selected index.
Arguments:
index
any
true
null
insertAt(position=[integer], value=[any])
Append a value to an array
Arguments:
position
integer
true
null
value
any
true
null
isDefined(index=[any])
Returns whether there exists an item in the array at the selected index.
Arguments:
index
any
true
null
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:
delimiter
String
false
,
initialValue
any
false
null
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:
callback
function:Function
true
null
parallel
boolean
false
false
maxThreads
integer
false
null
initialValue
any
false
null
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:
array2
array
true
null
leaveIndex
boolean
true
false
mid(start=[integer], length=[integer])
Extracts a sub array from an existing array.
Arguments:
start
integer
true
1
length
integer
false
0
pop(defaultValue=[any])
Remove last item in array and return it
Arguments:
defaultValue
any
false
null
prepend(value=[any])
Append a value to the start an array
Arguments:
value
any
true
null
push(value=[any])
Adds an element or an object to the end of an array, then returns the size of the modified array.
Arguments:
value
any
true
null
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:
to
numeric
false
null
reduce(callback=[function:BiFunction], initialValue=[any])
Run the provided udf over the array to reduce the values to a single output
Arguments:
callback
function:BiFunction
true
null
initialValue
any
false
null
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:
callback
function:BiFunction
true
null
initialValue
any
false
null
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:
size
any
true
null
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:
start
any
true
null
end
any
true
null
value
any
true
null
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:
defaultValue
any
false
null
slice(start=[integer], length=[integer])
Extracts a sub array from an existing array.
Arguments:
start
integer
true
1
length
integer
false
0
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:
callback
function:Predicate
true
null
parallel
boolean
false
false
maxThreads
integer
false
null
initialValue
any
false
null
sort(sortType=[any], sortOrder=[string], localeSensitive=[boolean], callback=[function:Comparator])
Sorts array elements.
Arguments:
sortType
any
false
textnocase
sortOrder
string
false
asc
localeSensitive
boolean
false
null
callback
function:Comparator
false
null
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:
index
Integer
true
null
elementCountForRemoval
Integer
false
0
replacements
array
false
null
swap(position1=[any], position2=[any])
Swaps array values of an array at specified positions.
This function is more efficient than multiple assignment statements
Arguments:
position1
any
true
null
position2
any
true
null
toJSON(queryFormat=[string], useSecureJSONPrefix=[string], useCustomSerializer=[boolean])
Converts a BoxLang variable into a JSON (JavaScript Object Notation) string.
Arguments:
queryFormat
string
false
row
useSecureJSONPrefix
string
false
false
useCustomSerializer
boolean
false
null
toList(delimiter=[String], initialValue=[any])
Used to iterate over an array and run the function closure for each item in the array.
Arguments:
delimiter
String
false
,
initialValue
any
false
null
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:
object
any
true
null
Examples
Last updated
Was this helpful?