Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • JS Tutorial
  • JS Exercise
  • JS Interview Questions
  • JS Array
  • JS String
  • JS Object
  • JS Operator
  • JS Date
  • JS Error
  • JS Projects
  • JS Set
  • JS Map
  • JS RegExp
  • JS Math
  • JS Number
  • JS Boolean
  • JS Examples
  • JS Free JS Course
  • JS A to Z Guide
  • JS Formatter
Open In App
Next Article:
JavaScript Array length
Next article icon

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); 

Output
3 0 4 

Syntax:

string.length

Return 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 Links

  • JS String Complete reference
  • Interesting Facts About JS Strings
  • JS String Exercise

Next Article
JavaScript Array length

K

Kanchan_Ray
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • javascript-string
  • JavaScript-Properties

Similar Reads

  • JavaScript String Methods
    JavaScript strings are the sequence of characters. They are treated as Primitive data types. In JavaScript, strings are automatically converted to string objects when using string methods on them. This process is called auto-boxing. The following are methods that we can call on strings. slice() extr
    12 min read
  • 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
    3 min read
  • JavaScript Array length
    JavaScript array length property is used to set or return the number of elements in an array. [GFGTABS] JavaScript let a = ["js", "html", "gfg"]; console.log(a.length); [/GFGTABS]Output3 Setting the Length of an ArrayThe length property can also be used to set the lengt
    2 min read
  • JavaScript typedArray.length() Method
    The typedArray.length is an inbuilt property in JavaScript which is used to return the length of the given typedArray. Syntax: typedArray.length Parameters: It does not accept any parameter because it is a property not a function. Return value: It returns the length of the given typedArray. Example
    2 min read
  • How to Get the Length of a String in Bytes in JavaScript ?
    In JavaScript, determining the length of a string in characters is straightforward using the length property. However, in many cases, particularly when dealing with file sizes, network protocols, or database storage, you might need to know the length of a string in bytes. This is because characters
    3 min read
  • JavaScript - How to Count Words of a String?
    Here are the various methods to count words of a string in JavaScript. 1. Using split() MethodThe simplest and most common approach is to use the split() method to divide the string into an array of words and count the length of the array. [GFGTABS] JavaScript const count = (s) => s.trim().split(
    3 min read
  • How to Find the Length of an Array in JavaScript ?
    JavaScript provides us with several approaches to count the elements within an array. The length of an array lets the developer know whether an element is present in an array or not which helps to manipulate or iterate through each element of the array to perform some operation. Table of Content Usi
    3 min read
  • SVG DOMStringList.length Property
    The SVG DOMStringList.length property returns the length of the given DOMStringList element. Syntax: len= DOMStringList.Length Return value: This property returns the length of the DOMStringList. Example 1: C/C++ Code <!DOCTYPE html> <html> <body> <svg width="350" heig
    1 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 func
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences