How to Find Length of String in JavaScript?

Last updated on June 1, 2023 by Ayaz Ali Shah

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.



Example 1:

Let’s find the 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.

// Output: 10

Example 2

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

let today = "Wednesday";
// 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.

Share on:

Related Posts

Tags: JavaScript, String,