Posted inJavaScript / jQuery

javascript string length trim, trimLeft, trimRight, toLowerCase and toUpperCase Best 5 Example

javascript string length: Strings are a crucial part of all programming languages. here we can learn to string.length : returns the number of total characters in a string with best 5 Examples with demo.

Best Javascript String Functions

  • Get String Length
  • trim() method
  • String trimLeft()
  • String trimRight()
  • String toLowerCase()
  • String toUpperCase()

javascript string length

In JavaScript, the syntax for javascript string length is:

string.length;

Example : 1 Interesting Fact

var live_str = 'Pakainfowebsite';

console.log(live_str.length);

JavaScript String length Property

index.html







Results:

24

don’t Miss : String methods in JavaScript

How TO – Get The Length of a String?

var str = "AB98CDEF256GHIJ45841KL6024485MNOPQR98964STUV56875WXYZ";
var len = str.length;

Finding Number of Characters in a String


let user_str = "";
let len = user_str.length;
console.log(len); // 0

user_str = "I love Pakainfo.";
len = user_str.length;
console.log(len); // 16

user_str.length = 5;
console.log(user_str); // I love Pakainfo.

Output

0
16
I love Pakainfo.

Example : 2 Javascript String Length

let user_str = "Pakainfo.com is great.";

if (user_str.length <= 20) {
 console.log("user_str is a short string");
} else {
 console.log("user_str is a long string");
}

print Line by line

for (let i = 0; i < user_str.length; i++) {
 console.log(user_str[i].toUpperCase());
}

Javascript string length, string trim

trim() method

trim() method : syntax

string.trim();

Example

	var movie_site = " It is a tamilblasters ";
	document.write("$" + movie_site + "$" + "
"); document.write("$" + movie_site.trim() + "$");

String trimLeft()

syntax

string.trimLeft();

Example

var movie_site = " It is a tamilblasters ";
document.write("$" + movie_site + "$" + "
"); document.write("$" + movie_site.trimLeft() + "$");

String trimRight()

syntax

string.trimRight();

Example

var movie_site = " It is a tamilblasters ";
document.write("$" + movie_site + "$" + "
"); document.write("$" + movie_site.trimRight() + "$");

don't Miss : JavaScript String Methods with Example

String toLowerCase()

syntax

string.toLowerCase()

Example

var movie_site = " It is a tamilblasters ";
	document.write(movie_site.toLowerCase());

String toUpperCase()

syntax

string.toUpperCase()

Example

var movie_site = " It is a tamilblasters ";
	document.write(movie_site.toUpperCase());

I hope you get an idea about javascript string length.
I would like to have feedback on my infinityknow.com.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype