How to Find Length of String in JavaScript?

Last updated on June 1, 2023

In JavaScript we can find the length of string through the length property. You can attach the length property directly with a string to find the length.

The JavaScript length property returns the length of the string with the number data type.

Syntax

string.length

Example 1:

Let’s find the JavaScript length.

"Javascript".length;
// Output: 10

In this example, we have a string that contains JavaScript and the length property is attached to the string to find the length. This script returns 10 in the output because there are 10 alphabetic letters in JavaScript.

You can pass the script into the console.log() function to see the output in the console.

console.log("Javascript".length);
// Output: 10

Example 2

Let’s create a variable and store a string into it.

let today = "Wednesday";
today.length;
// Output: 9

In this example a string is stored into the today variable and length property is attached with the variable that returns length of the variable’s value.


Written by
I am a skilled full-stack developer with extensive experience in creating and deploying large and small-scale applications. My expertise spans front-end and back-end technologies, along with database management and server-side programming.

Share on:

Related Posts

Tags: JavaScript, String,