I have an array of sprites called segments
and I would like to skip the first element of segments
in my for each loop. I'm doing this at the moment:
var first = true;
for each (var segment in this.segments)
{
if(!first)
{
// do stuff
}
first == false;
}
Is there a better way to do this? Thanks!
Use iter() and next() to skip first element of a for-loop User iter(object) to return an iterable for any iterable object . Call next(iterator) on iterator as the iterable for object to skip the first element of iterator .
The shift() method removes the first element from an array and returns that removed element.
if its an array why not just:
for(var i:int = 1; i < this.segments.length; i++)
{
}
This can also be done via "slice". For example
for (var segment in this.segments.slice(1))
{
}
Array#slice
will copy the array without the first element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With