Get the length of a string in JavaScript

How to get the length of a string using JavaScript

Posted by Ervin Adams on September 5, 2022

Get the length of a string in JavaScript

How to get the length of a string using JavaScript

Posted by Ervin Adams on September 5, 2022

Here is how you can get the length of a string in JavaScript.

  • Use the length property
  • The length property is read only 
  • Spaces within the string are counted as well

Here is an example below:

let str = "this is a string";
console.log(str.length); // 16

 

Any question?
This field is required
Your question have been successfully submitted and will be reviewed before published
Please login to ask a question