The Complete WebDeveloper (38 Blogs) Become a Certified Professional
AWS Global Infrastructure

Front End Web Development

Topics Covered
  • AngularJS (44 Blogs)
  • The Complete WebDeveloper (34 Blogs)
  • ReactJS (11 Blogs)
  • JavaScript and JQuery Essentials Training (2 Blogs)

How to Implement String Length in JavaScript

Last updated on Jun 21,2023 2.3K Views

28 / 31 Blog from JavaScript

JavaScript is one of the most widely used programming languages. It is also quite popular for its versatility across the platforms. Some of the most popular frameworks based on JavaScript are Angular, React, Node.js, Vue.js, etc. In this article, we will discuss String Length in JavaScript in the following order:


String Manipulation

JavaScript provides several methods of string manipulation function which comes in handy when handling the data entered by the user through any forms and so. They help to modify the data according to our use.

Some of the most used string manipulation functions are the following:

  • String Length:

Used to find the length of any particular string.

  • Finding string in a string:

    Indexof() can be used to locate any particular string in and other string.

    lastIndexOf() returns the last occurrence of any particular string in a string.

  • slice()

This method is used for getting a part of a string.

It takes on two parameters, starts and end for the output and returns the values according to that.

  • replace()

This function takes on two parameters, the one which is to be replaced and the other which will replace the first parameter in the string.

  • toUpperCase()

This function converts the whole string to the upper case.

  • concat()

This function concatenates the two parameters which are passed on.

  • string.trim()

This function removes all the white spaces from the string which are present either in the start or the end of the string.

  • split()

This function converts a string into an array.


The above function call would convert the string stored in the variable txt to the array with commas (,) separating them.

Let’s get back to the main motive of this blog which is to discuss string length in JavaScript.


String Length in JavaScript

The length property of a String object indicates the length of a string, in UTF-16 code units.

var str = 'Life, the universe and everything. Answer:';
console.log(str + ' ' + str.length);

The above variable “str” which is of var type has a string stored in it.

In the console.log function, the str.length would return the length of the string stored in the str variable.


String Length in JavaScript

42 is returned as the answer as 42 is the length of the string.

With this, we come to the end of this String Length in JavaScript. I hope this blog was helpful for you to know about the string manipulation in JavaScript as well as made you all well acquainted with the different string manipulation functions which are available for our use.

Check out the Web developer course by Edureka. Web Development Certification Training will help you learn how to create impressive websites using HTML5, CSS3, Twitter Bootstrap 3, jQuery and Google APIs and deploy it to Amazon Simple Storage Service(S3). 

Check out the Angular Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe. Angular is a JavaScript framework that is used to create scalable, enterprise, and performance client-side web applications. With Angular framework adoption being high, performance management of the application is community-driven indirectly driving better job opportunities.

If you want to get trained in React and wish to develop interesting UI’s on your own, then check out the Best React JS Course by Edureka, a trusted online learning company with a network of more than 250,000 satisfied learners spread across the globe.

Take your design skills to the next level with our UI UX Design Course Online.

Got a question for us? Please mention it in the comments section of “String Length in JavaScript” and we will get back to you.

Upcoming Batches For Web Developer Certification Training Course
Course NameDateDetails
Web Developer Certification Training Course

Class Starts on 17th August,2024

17th August

SAT&SUN (Weekend Batch)
View Details

Join the discussion

Browse Categories

webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.

image not found!
image not found!

How to Implement String Length in JavaScript