JavaScript string.length Last Updated : 16 Nov, 2024 Comments Improve Suggest changes Like Article Like Report The string.length is a property in JS which is used to find the length of a given string. The string.length property returns 0 if the string is empty. javascript let s1 = 'gfg'; console.log(s1.length); let s2 = ''; console.log(s2.length); let s3 = '#$%A'; console.log(s3.length); Output3 0 4 Syntax:string.lengthReturn Values: It returns the length of the given string.In JavaScript arrays also have length property to find length of an array. But unlike arrays, we cannot change length of string using length properly because strings are immutable in JS. JavaScript let a = ["js", "css", "html"]; a.length = 2; // Changes length of array console.log(a); let s = "geeksforgeeks" s.length = 3; // Has no effect on string console.log(s); Output[ 'js', 'css' ] geeksforgeeks Recommended LinksJS String Complete referenceInteresting Facts About JS StringsJS String Exercise Comment More infoAdvertise with us Next Article JavaScript string.length K Kanchan_Ray Follow Improve Article Tags : JavaScript Web Technologies javascript-string JavaScript-Properties Similar Reads JavaScript String length Property The JavaScript length property is a fundamental feature used to determine the number of characters in a string. It is essential for various string operations, such as validation, manipulation, and iteration. Understanding how to effectively use the length property can simplify tasks like checking in 2 min read JavaScript Array length JavaScript array length property is used to set or return the number of elements in an array. JavaScriptlet a = ["js", "html", "gfg"]; console.log(a.length);Output3 Setting the Length of an ArrayThe length property can also be used to set the length of an array. It allows you to truncate or extend t 2 min read jQuery length property The length property is used to count a number of the elements of the jQuery object. Syntax: $(selector).length where the selector is the object whose length is to be calculated. Return Values: It returns the length of the selector. Below is the example to show the working of the jQuery length proper 1 min read TypeScript String Length Property The length property in TypeScript is a read-only attribute used to get the number of characters in a string, including spaces and special characters. It returns an integer representing the total length of the string.Syntaxstring.length Return Value: This method returns the length to the String funct 2 min read Can we Change the Length of a JS String using Length Property? The length property of a string returns the number of characters in the string, including spaces, punctuation, and special characters. It is a read-only property, which means that you cannot assign a new value to length directly to change the string's size. The given below example shows that you can 1 min read HTML DOM length Property The DOM length property in HTML is used to get the number of items in a NodeList object. A NodeList is a collection of child Nodes. For example, the NodeList of the body will contain all the child nodes in the body i.e. paragraphs, comments, headings, script, etc.Syntax: nodelist.lengthReturn Value: 2 min read How to define a new method for calculating the actual length of string in JavaScript using prototype ? In JavaScript, you can use the String. length property to get the length of a string variable. This method will give you a string that is enclosed in quotes no matter what it is. We will get one issue while using this String. length method. Let's discuss when we will get the issue with that String.l 3 min read JavaScript - Length of an Array in JS These are the following approaches to find the length of the given array: 1. Using length Property - Mostly UsedIn this approach, we have used the length property to determine the length of an array.JavaScriptlet a = [12, 4.7, 9, 10] console.log(a.length)Output4 2. Using for of and for in LoopWe hav 1 min read Java String length() Method String length() method in Java returns the length of the string. In this article, we will see how to find the length of a string using the String length() method.Example:Javaclass Geeks { public static void main(String[] args){ String s1 = "abcd"; System.out.println(s1.length()); String s2 = ""; Sys 2 min read StringBuilder length() in Java with Examples The length() method of StringBuilder class returns the number of character the StringBuilder object contains. The length of the sequence of characters currently represented by this StringBuilder object is returned by this method. Syntax: public int length() Return Value: This method returns length o 2 min read Like