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.

Leave a Comment