Categories:
Partners
Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

Creating dense arrays

A dense array allows programmers to efficiently declare an array when the initial values of the array is known beforehand. Dense arrays are supported in all major browsers. But before we officially get to dense arrays, lets review the syntax for a regular array first.

Quick review of declaring a "normal" array

By default, values are entered into an array first by declaring it, then storing the values into its elements, one by one:

var myarray=new Array(3)
myarray[0]="one"
myarray[1]="two"
myarray[2]="three"

The above method of entering values into an array works just fine in most situations. However, don't you wish there were a more efficient way of doing the same thing, especially when the array is quite large?

Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.