All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

JavaScript Length Of Array

Last Updated : Mar 11, 2024

JavaScript Length Of Array

In this tutorial we will show you the solution of JavaScript length of array, as we know array always had more than one values so we defined array with some values then when we appending length property with array variable it returns count of values defined in array as result and we printed on console.

Just follow the steps and below.

Step By Step Guide On JavaScript Length Of Array :-

Here we defined variable array ‘arr’ with four string values if you wish to modify array values then you can change it and for finds length of array we needs to append ‘length’ property with that array variables ‘arr’ then returns result stored on variable ‘res’.

Then we printed result on console by console.log() method with array ‘arr’, some string and result variable ‘res’.

<!DOCTYPE html&g;
<html&g;
    <head&g;
        <title&g;ARRAY LENGTH</title&g;
    </head&g;
    <body&g;
        <script&g;
            var arr = [ "Duke","KTM","ZR","BMW" ];
            var res=arr.length;
            console.log(arr+" Array Length is "+res);
        </script&g;
    </body&g;
</html&g;
  1. <!DOCTYPE html&g; tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html&g; tag is used to indicate the beginning of HTML document.
  3. As above shown <head&g; tag is contain information about webpage and external file links are declared here. <title&g; tag is used for set the webpage title.
  4. Both <head&g; and <title&g; tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  5. <body&g; tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  6. In script we defined variable ‘arr’ with keyword ‘var’ there we initialized string values ‘[ "Duke","KTM","ZR","BMW" ]’. Next we need to use length property/statement for finds out length of array ‘arr’.
  7. So we appended length with array ‘arr’ and it returns stored on variable ‘res’. At last we printed using console.log() result on console with variable arr, string ‘Array Length is’, variable ‘res’.
  8. In script we know that for print on console we need to use console.log() method and for open console panel right click on window tab select ‘inspect’ then panel will open there you have to click console tab.
  9. Both </body&g;,</html&g; tags closed respectively. </body&g; tag indicates the end of body, Then </html&g; tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to use length statement in javascript.

When we executes program on browser we can’t see the result because we printed on console panel so we have to use shortcut ‘ctrl+shift+j’ then console panel will open at right hand side with results of ‘Duke,KTM,ZR,BMW Array Length is 4’.

If your need to define variable ‘arr’ with some other integer values then you can modify it in this concept accordingly.

I hope this tutorial on JavaScript length of array helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪