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.
In the following web document length property is used to get the number of elements of a given array.
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); newParagraph.appendChild(newText); document.body.appendChild(newParagraph);
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join