javascript string length – How To Get The Length of a String in JavaScript?

javascript string length – The length property returns the length of a string. The length of an empty string is 0. Parameter: It does not accept any parameter. This property returns the number of characters in a string.

javascript string length – JavaScript String length Property

What is Javascript Length?

Syntax of Javascript Length function


here returns the length of X

Using Javascript Length on strings:

const results = "Greeting Message!";


Using Javascript Length on Arrays:

const results = ['computer', 'laptop', 'dvd', 'cd'];


Finding Number of Characters in a String

Simple Javascript program to get length of strings

let final_con = "";
let len = final_con.length;

final_con = "We love Payment.";
len = final_con.length;

final_con.length = 5;

Return the number of characters in a string:

Read Also:  Javascript Forms Required Fields validation Example

var userInput = "Greeting Message!";
var n = userInput.length;

String Length

var userInput = "Stripe Payment Gateway";
	var length = userInput.length;
	alert( "Length is "+length);

String trimLeft()

var userInput = " Stripe Payment Gateway Integration using PHP ";
	document.write("$" + userInput + "$" + "<br>");
	document.write("$" + userInput.trimLeft() + "$");

String toUpperCase()

var userInput = " This is a string ";

Don’t Miss : String Length Javascript

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