Javascript - Array length Property

The length property sets or returns the number of elements in an array.

Description

The length property sets or returns the number of elements in an array.

Syntax

To get the length of an array:

array.length

To set the length of an array:

array.length = number

Return

A Number, representing the number of elements in the array object

Example

Return the length of an array:

Demo

var myArray = ["XML", "Json", "Database", "Mango"];
console.log( myArray.length);/* w ww.j av  a  2  s.c  om*/

//set length
myArray.length = 2;

console.log( myArray.length);
console.log( myArray);

Result