React JS Training Course Online
- 21k Enrolled Learners
- Weekend
- Live Class
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:
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.
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:
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.
Course Name | Date | Details |
---|---|---|
Web Developer Certification Training Course | Class Starts on 28th December,2024 28th December SAT&SUN (Weekend Batch) | View Details |
Web Developer Certification Training Course | Class Starts on 4th January,2025 4th January SAT&SUN (Weekend Batch) | View Details |
edureka.co