JavaScript | length of string and array objects
The length property of the JavaScript object is used to find out the size of that object. This property is used with many objects like JavaScript string, JavaScript array, etc. In case of strings, this property returns the number of characters present in the string. In case of an array, this property returns the number of elements present in the array.
Syntax: object.length where the object can either be a string object or an array object
Examples:
Input : print("GeeksForGeeks".length)
Output :13
Input : print([1, 2, 3, 4, 5, 6, 7, 8, 9].length)
Output :9
Explanation:
In the first example 13 is the number of character in the string “GeeksForGeeks”, hence the output is 13.
And likewise in second example the length of the array is 9 and so is the output
Program:
<script> // JavaScript to illustrate length property function func() { // length property for array document.write([1,2,3,4,5,6,7,8,9].length); document.write("<br>"); // length property for string document.write("GeeksForGeeks".length) } func(); </script> |
Output:
9 13
Recommended Posts:
- Sort array of objects by string property value in JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- Max/Min value of an attribute in an array of objects in JavaScript
- How to remove duplicates from an array of objects using JavaScript ?
- JavaScript | string.length
- How to pad a string to get the determined length using JavaScript ?
- Extract unique objects by attribute from array of objects.
- JavaScript | Array length Property
- Objects in Javascript
- JavaScript | Objects
- JavaScript | Date Objects
- Creating objects in JavaScript (3 Different Ways)
- How to get character array from string in JavaScript?
- How to merge properties of two JavaScript objects dynamically?
- Convert comma separated string to array using JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



