Saturday, November 16, 2024
Google search engine
HomeLanguagesJavascriptHow to get the size of an array in JavaScript ?

How to get the size of an array in JavaScript ?

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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments