Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

JavaScript: Sparse arrays

In Sparse Arrays, elements need not have contiguous indexes.

var arr1 = new Array();
arr1[100] = "Hello";
arr1[1234] = 432156;

Eventhough we entered only two elements into the array arr1, the Length of the array is 1235 (maximum index + 1 = 1234+1).

sparse.html





sparse arrays



"text/javascript">
var arr1 = new Array();
arr1[100] = "Hello";
arr1[1234] = 432156;

document.write("arr1 length : " + arr1.length);





Open above document in browser, you can able to see following text.

arr1 length : 1235

For dense array the length of the array is equal to number of elements in the array, where as for sparse arrays the length of the array can be greater than the number of elements in the array.

Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

JavaScript: Sparse arrays

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×