In the previous article on Arrays in Javascript, we have seen detailed information about arrays and their methods in Javascript. In this article, we will how to find out the length of any Javascript array.
JavaScript Array length Property: The JavaScript Array Length returns an unsigned integer value that represents the number of elements present in the array. The value is non-negative and always a 32-bit integer.
Example 1: In this example we will store a string inside of an array and find out the length of that array.
Javascript
<script> // Defining an String array let arr1= [ "Eat" , "Code" , "sleep" , "Repeat" ]; // Storing length of arr1 in len1 variable let len1=arr1.length; // Displaying the length of arr1 console.log( "Length of the Array:" +len1); </script> |
Output:
Length of the Array: 4
Example 2: In this example we will store a number inside of an array and find out the length of that array.
Javascript
<script> // Defining an number array let arr2= [100,200,300,400,500]; // Storing length of arr2 in len2 variable let len2=arr2.length; // Displaying the length of arr2 console.log( "Length of arr2:" +len2); </script> |
Output:
Length of arr2: 5