JavaScript length Property: Array Object


The length property returns number elements of an array. The value of the length property is an integer and less than 232. The length property is also used to truncate an array. If the length property is set with a number which is greater than the original length then new elements are added to the end of the array. If the length property is set with a number which is less than the original length then excess elements at the end of the array are lost.


Implemented in JavaScript 1.1




In the following web document length property is used to get the number of elements of a given array.


<!DOCTYPE html>
<html lang="en">
<meta charset="utf8" />
<title>JavaScript Array object-length Property example</title>
<style type="text/css">
h1 {color:red}
<h1>JavaScript Array Object : length Property</h1>
<script src="array-length-example1.js">

JS Code

var myarray = new Array("Orange", "Apple", "Banana", "Cherry", "Mango");
var newParagraph = document.createElement("p");
var newText = document.createTextNode("The length of the array is : "+myarray.length); 

View the example in the browser

Practice the example above online

JavaScript Array object-length Property example

See also:

JavaScript input Property: Array Object

Previous: JavaScript index Property: Array Object
Next: JavaScript prototype Property: Array Object

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.