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.

@:genericstaticinlinefastSplice<T>(array:Array<T>, element:T):Array<T>

Safely removes an element from an array by swapping it with the last element and calling pop() (won't do anything if the element is not in the array). This is a lot faster than regular splice(), but it can only be used on arrays where order doesn't matter.

Parameters:

array

The array to remove the element from

element

The element to remove from the array

Returns:

The array

@:genericstaticflatten2DArray<T>(array:Array<Array<T>>):Array<T>

Flattens 2D arrays into 1D arrays. Example: [[1, 2], [3, 2], [1, 1]] -> [1, 2, 3, 2, 1, 1]

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

@:has_untyped@:genericstaticsetLength<T>(array:Array<T>, newLength:Int):Array<T>

Sets the length of an array.

Parameters:

array

The array.

newLength

The length you want the array to have.

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

@:genericstaticinlineswapAndPop<T>(array:Array<T>, index:Int):Array<T>

Removes an element from an array by swapping it with the last element and calling pop(). This is a lot faster than regular splice(), but it can only be used on arrays where order doesn't matter.

IMPORTANT: always count down from length to zero if removing elements from within a loop

using flixel.util.FlxArrayUtil;

var i = array.length;
while (i-- > 0)
{
     if (array[i].shouldRemove)
     {
          array.swapAndPop(i);
     }
}

Parameters:

array

The array to remove the element from

index

The index of the element to be removed from the array

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