On 11/04/2013 18:30, Dave Glasser wrote:

In Java and other C-derived languages, an array literal can have a comma after the last element, for example:

int[] numList = {1, 2, 3,};

In ActionScript, you can do the same thing:

var numList:Array = [1, 2, 3,];

In both cases, the array has a length of 3. The trailing comma is basically ignored, it's permitted to make moving the elements around in the editor easier, I assume.

I noticed something else today about array literals in actionscript. You can pretty much add additional commas wherever you want:

var numList:Array = [ ,  , ,1, 2, , 3,,,];

And except for the final trailing comma, the array will have an element for each of those commas. The element will be null or undefined where there is no actual value.

I was surprised when I discovered this, because I would swear I've had compiler errors over misplaced commas in array literals before. Am I imagining things?

I checked the AS3 programmers reference, and googled around to other pages, and nowhere could I find any documentation of this behavior.

Is this a bug, or a feature?

Does it really matter? Nobody in their right mind is going to be populating arrays with multiple commas.

Reply via email to