A set of functions for array manipulation.

Static methods

@:value({ recursive : false })staticclearArray<T>(array:Array<T>, recursive:Bool = false):Array<T>

Clears an array structure, but leaves the object data untouched Useful for cleaning up temporary references to data you want to preserve. WARNING: Does not attempt to properly destroy the contents.

Parameters:

array

The array to clear out

Recursive

Whether to search for arrays inside of arr and clear them out, too

staticinlinecontains<T>(array:Array<T>, element:T):Bool

staticequals<T>(array1:Array<T>, array2:Array<T>):Bool

Compares the contents with == to see if the two arrays are the same. Also takes null arrays and the length of the arrays into account.

staticlast<T>(array:Array<T>):Null<T>

Returns the last element of an array or null if the array is null / empty.

staticinlinesafeContains<T>(array:Null<Array<T>>, element:T):Bool

Returns true if the array is not null and contains the element.

Available since

5.0.0

.

staticsafePush<T>(array:Null<Array<T>>, element:T):Array<T>

Pushes the element into the array (and if the array is null, creates it first) and returns the array.

Available since

4.6.0

.

staticinlinesafeSwap<T>(array:Array<T>, item1:T, item2:T):Array<T>

Swaps two items, item1 and item2 which are in the array, but only if both elements are present in the array

Parameters:

array

The array whose elements need to be swapped

item1

One of the elements of the array which needs to be swapped

item2

The other element of the array which needs to be swapped

Returns:

The array

staticinlinesafeSwapByIndex<T>(array:Array<T>, index1:Int, index2:Int):Array<T>

Swaps two elements of an array, which are located at indices index1 and index2 and also checks if the indices are valid before swapping

Parameters:

array

The array whose elements need to be swapped

index1

The index of one of the elements to be swapped

index2

The index of the other element to be swapped

Returns:

The array

staticinlineswap<T>(array:Array<T>, item1:T, item2:T):Array<T>

Swaps two items, item1 and item2 which are in the array

Parameters:

array

The array whose elements need to be swapped

item1

One of the elements of the array which needs to be swapped

item2

The other element of the array which needs to be swapped

Returns:

The array

staticinlineswapByIndex<T>(array:Array<T>, index1:Int, index2:Int):Array<T>

Swaps two elements of an array, which are located at indices index1 and index2

Parameters:

array

The array whose elements need to be swapped

index1

The index of one of the elements to be swapped

index2

The index of the other element to be swapped

Returns:

The array