Sunday, February 17, 2008

var motto:Array = [ "rock", "on", ];

When adding/removing an element in an array, how many times do you find yourself having to deal with the nuisance of adding/removing the comma of the last array element? Well not anymore. In AS3, you are allowed to leave your comma for the last element in. Perl coders have been able to do this for years, finally Actionscript coders can too.

4 Comments:

Blogger Andrew Blair said...

Can you explain a situation where there would be an extra comma? I don't think I've run into that before.

10:22 AM  
Blogger boon said...

One instance is when you have an array of long strings, where you format things to be one string per line for readability.

e.g.

var countryName:Array = [
"Tahiti",
"Jamaica",
"Bahamas"
];

12:34 AM  
Blogger Andrew Blair said...

Oh I see what you mean now. So the compiler's OK with the extra comma and doesn't create a null item on the end of the array ?

8:47 AM  
Blogger boon said...

Yes you got it.

7:08 PM  

Post a Comment

<< Home