Papa De Beau
Papa De Beau

Reputation: 3828

AS3 CHANGING the order of an Array - eliminate zero?

I have an array of 10 items.

var myArray:Array = ["One", "Two", "Three","Four", "Five", "Six","Seven", "Eight", "Nine","Ten"];

I would like to keep these same ten items but want the array to start with 1 and not 0.

For example if I called.

trace(myArray[1]); // this should display "One";

if did this...

trace(myArray[7]); // this should display "Seven";

What SIMPLE function could I write to change this order?

Upvotes: 0

Views: 116

Answers (2)

Benny
Benny

Reputation: 2228

function returnArrayVal(i:uint):*{  
    return myArray[--i];
}
trace(returnArrayVal(5));

Upvotes: 0

Vesper
Vesper

Reputation: 18747

Add "Zero" as the first element of that array. Should do :)

Upvotes: 1

Related Questions