How to get the size of an array in JavaScript ?
Last Updated :
17 Nov, 2022
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>
let arr1= [ "Eat" , "Code" , "sleep" , "Repeat" ];
let len1=arr1.length;
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>
let arr2= [100,200,300,400,500];
let len2=arr2.length;
console.log( "Length of arr2:" +len2);
</script>
|
Output:
Length of arr2: 5
Share your thoughts in the comments
Please Login to comment...