The Array Length Property

By: Dusty Arlia
Published on September 13, 2012
Last Updated on Wednesday, July 15, 2015 at 6:08 PM
Total Updates: 7

Arrays hold lists of items. If you ever want to know how many items are in an array, use the length property to determine the number of items. If you had an array named slideshowPictures and you wanted to know how many pictures were in that array, use this code:

slideshowPictures.length

This code returns the number of items in the array named slideshowPictures. If you wanted to display that number in a dialog box, use the alert() method like this:

alert(slideshowPictures.length);

Remember that array index numbers start at 0 not 1. The length property counts the item in the [0] index spot. So if the array has items assigned all the way up to slideshowPictures[9], then there should be 10 items. More specifically, there is 10 elements in this array. The actual values assigned to these elements are not looked at. The length property is only concerned about how many elements are in the array, not their values.

Comments:

Ad:

Ad: