JavaScript and JQuery Essentials Trainin... (56 Blogs) Become a Certified Professional
AWS Global Infrastructure

Front End Web Development

Topics Covered
  • AngularJS (29 Blogs)
  • jQuery UI Development (2 Blogs)
  • The Complete WebDeveloper (38 Blogs)
  • ReactJS (7 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

How to Implement String Length in JavaScript

Published on Oct 22,2019 90 Views
How to Implement String Length in JavaScript

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

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.

txt.split(“,”)

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.

Output:

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 Development Certification Training 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). 

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

Comments
0 Comments

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
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.