How to use Array Length in JavaScript
In this article I have described about Array Length property used in JavaScript.
JavaScript Array length Property
- As mentioned earlier that for storing multiple values in a single variable we use array object .
- The array object has a property is known as length Property.
- With the help of length Property we can set and return the number of elements array object .
Browser support
Following are the main browsers which support the the length Property of array object
- Internet Explorer.
- Firefox.
- Opera.
- Google Chrome.
- Safari.
Syntax
The length Property of array object has following syntax
array.length
Lets take an example
<!DOCTYPE html>
<html>
<body style ="background-color:green">
<p id="menu">CHECK THE LENGTH OF AN ARRAY</p>
<button onclick="myFunction()">CLICK</button>
<script type="text/javascript">
function myFunction() {
var array = ["AMAN", "SHUBHAM", "NITIN", "AMAN", "vipin"];
var x = document.getElementById("menu");
x.innerHTML = array.length;
}
</script>
</body>
</html>
|
Output
When we click on button
Further Readings
You may also want to read these related articles :here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here