Array

class Array<T>Available in flash8, flash, neko, js, php, cpp, cs, javaAn Array is one of several data-structures used to store values. var length(default,null) : IntAvailable in cs, javaThe length of the Array. (Read Only) var length(default,null) : IntAvailable in flash8, flash, neko, js, php, cppThe length of the Array. (Read Only) function new() : VoidCreates a new Array. function concat( a : Array<T> ) : Array<T>Available in cs, javaReturns a new Array by appending a to this. function concat( a : Array<T> ) : Array<T>Available in flash8, flash, neko, js, php, cppReturns a new Array by appending a to this. function copy() : Array<T>Available in cs, javaReturns a copy of the Array. The values are not copied, only the Array structure. function copy() : Array<T>Available in flash8, flash, neko, js, php, cppReturns a copy of the Array. The values are not copied, only the Array structure. function filter( f : T -> Bool ) : Array<T> function insert( pos : Int, x : T ) : VoidAvailable in cs, javaInserts the element x at the position pos. All elements after pos are moved one index ahead. If "pos" is bigger than the array length element "x" will be inserted at position "pos" and default values will fill in-between. (Default values are null on 'dynamic' platforms, actual values on 'static' platforms. So Array<Int> empirically has 0 as the default value on hxcpp.) function insert( pos : Int, x : T ) : VoidAvailable in flash8, flash, neko, js, php, cppInserts the element x at the position pos. All elements after pos are moved one index ahead. If "pos" is bigger than the array length element "x" will be inserted at position "pos" and default values will fill in-between. (Default values are null on 'dynamic' platforms, actual values on 'static' platforms. So Array<Int> empirically has 0 as the default value on hxcpp.) function iterator() : Iterator<T>Returns an iterator of the Array values. function join( sep : String ) : StringAvailable in cs, javaReturns a representation of an array with sep for separating each element. function join( sep : String ) : StringAvailable in flash8, flash, neko, js, php, cppReturns a representation of an array with sep for separating each element. function map<S>( f : T -> S ) : Array<S> function pop() : Null<T>Available in cs, javaRemoves the last element of the array and returns it. function pop() : Null<T>Available in flash8, flash, neko, js, php, cppRemoves the last element of the array and returns it. function push( x : T ) : IntAvailable in cs, javaAdds the element x at the end of the array. Returns the new length of the array. function push( x : T ) : IntAvailable in flash8, flash, neko, js, php, cppAdds the element x at the end of the array. Returns the new length of the array. function remove( x : T ) : BoolAvailable in cs, javaRemoves the first occurence of x. Returns false if x was not present. Elements are compared by using standard equality. function remove( x : T ) : BoolAvailable in flash8, flash, neko, js, php, cppRemoves the first occurence of x. Returns false if x was not present. Elements are compared by using standard equality. function reverse() : VoidAvailable in cs, javaReverse the order of elements of the Array. function reverse() : VoidAvailable in flash8, flash, neko, js, php, cppReverse the order of elements of the Array. function shift() : Null<T>Available in cs, javaRemoves the first element and returns it. function shift() : Null<T>Available in flash8, flash, neko, js, php, cppRemoves the first element and returns it. function slice( pos : Int, ?end : Int ) : Array<T>Available in cs, javaCopies the range of the array starting at pos up to, but not including, end. Both pos and end can be negative to count from the end: -1 is the last item in the array. function slice( pos : Int, ?end : Int ) : Array<T>Available in flash8, flash, neko, js, php, cppCopies the range of the array starting at pos up to, but not including, end. Both pos and end can be negative to count from the end: -1 is the last item in the array.
function sort( f : T -> T -> Int ) : VoidAvailable in cs, java

Sort the Array according to the comparison function f.

f(x,y) should return:

  • 0 if x == y
  • >0 if x should appear after y
  • <0 if x should appear before y

function sort( f : T -> T -> Int ) : VoidAvailable in flash8, flash, neko, js, php, cpp

Sort the Array according to the comparison function f.

f(x,y) should return:

  • 0 if x == y
  • >0 if x should appear after y
  • <0 if x should appear before y

function splice( pos : Int, len : Int ) : Array<T>Available in cs, javaRemoves len elements starting from pos and returns them. function splice( pos : Int, len : Int ) : Array<T>Available in flash8, flash, neko, js, php, cppRemoves len elements starting from pos and returns them. function toString() : StringAvailable in cs, javaReturns a displayable representation of the Array content. function toString() : StringAvailable in flash8, flash, neko, js, php, cppReturns a displayable representation of the Array content. function unshift( x : T ) : VoidAvailable in cs, javaAdds the element x at the start of the array. function unshift( x : T ) : VoidAvailable in flash8, flash, neko, js, php, cppAdds the element x at the start of the array.
version #19305, modified 2013-05-08 11:13:01 by api
4 comments
  • Aug 29, 2012 at 23:53

    Clarified definition of array to include the stuff about Haxe's implementation of Array that's important to people migrating from other languages: that it can't have gaps, that it starts at 0, and it's only indexed by integers.
    Also added cross-refs to various other data-structures that might be what they are looking for if they came from another language.
    A Wiki (or any programming docs) with few cross-refs is a very sad thing: I hope these edits made it happier.

  • Feb 05, 2013 at 01:05

    If you are wondering if array[big#]=42 will work, it will; see the note at the top about there being no "gaps" in arrays.

  • amn
    May 11, 2013 at 19:10

    In AVM2 (ActionScript Virtual Machine, as used by Flash Player running SWF movies tagged as version 9 or later) Array.length is WRITABLE property. In haXe, it is read-only, and so if you want to truncate an array in AVM2, in haXe you would have to resort to the "untyped":

    untyped a.length = 0;
  • Nov 28, 2013 at 06:09

    To explicitely declare, say, a 2D array of Floats, you would do something like:

    var arr:Array<Array<Float>>;