JavaScript Tutorials

The length property

The number of items in an array is stored in the length property, which always returns 0 or more, as shown in the following example:

var colors = ["red", "blue", "green"]; //creates an array with three strings
var names = []; //creates an empty array
alert(colors.length); //3
alert(names.length); //0


Create an array with a few values and print the length of the array in the console.

var people = ['Bob', 'Jack', 'Marcy', 'Wilson'];