JavaScript Array length Property


JavaScript array length property returns an unsigned, 32-bit integer that specifies the number of elements in an array.

The length property returns the number of elements in an array in the form of a 32-bit unsigned integer. We can also say that the length property returns a number that represents the number of array elements. The return value is always larger than the highest array index.

The length property can also be used to set the number of elements in an array. We have to use the assignment operator in conjunction with the length property to set an array's length.

The array.length property in JavaScript is same as the array.size() method in jQuery. In JavaScript, it is invalid to use array.size() method so, we use array.length property to calculate the size of an array.

Syntax

array.length

Set the length of an array:

array.length = number

Example

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.length;

Example -