By the latest Coding Convention of ActionScript 3, the usage of the Array constructor is only encouraged for size allocation, e.g. var myArr:Array = new Array(2); for an array with 2 elements in it. In all other cases literals should be used, e.g. var myArr:Array = [];

Performance-wise this makes a lot of sense with up to 3 times of the speed difference:

new Array vs Array literals benchmark

The above chart displays 3 different tests through 1 000 000 iterations all confirming that Array literals are a lot faster in the circumstances.

So for creating an Array, use

var myArr:Array = [];

instead of

var myArr:Array = new Array();

Share and bookmark:

  • Twitter
  • Technorati
  • StumbleUpon
  • Digg
  • Google Bookmarks
  • Facebook
  • MySpace
  • del.icio.us
  • Mixx
  • blogmarks
  • Live
  • NewsVine
  • Reddit
  • Slashdot
  • LinkedIn
  • FriendFeed
  • email