This means that as long as you are adding values to the location specified
by the Array length, you would never overwrite existing values.
Pushing and Popping Values
Another way to perform the same trick is to use the push method. The push method ensures that the
value you wish to add to the Array is only appended to the very end of the Array:
var lastLocation : Int = myArray.push(44);
The push method returns the location of the last added value, which you can then use to further
manipulate the value if necessary. In the same manner, you can remove the very last item in the Array
using the pop method:
var poppedValue : Int = myArray.pop();
Once the last item is removed, the method returns the popped value rather than disregard it, in case you
want to deal with the value in some way.
Shifting and Unshifting Values
haXe Arrays also provide a means to add values to the start of the Array, by using the unshift method:
myArray.unshift(44);
The unshift method behaves in the same manner as the push method with the exception that Void is
returned, instead of the location id of the added value.
Pages:
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121