JavaScript string.length Last Updated : 16 Nov, 2024 Summarize Comments Improve Suggest changes Share 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 HTML DOM length Property 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 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 Like