offline version v3


59 of 264 menu

length property

The length property allows you to find out the length of a string. The length is the number of characters in a the string.

Syntax

string.length;

Example

Let the variable str store a string. Let's find its length:

let str = 'abcde'; console.log(str.length);

The code execution result:

5

Example

The length of a string also includes spaces. Let's find the length of the string that has a space:

let str = 'word1 word2'; console.log(str.length);

The code execution result:

11

See also

  • the padEnd method
    that pads the current string from its end with a given string
  • the padStart method
    that pads the current string from its start with a given string
  • the repeat method
    that creates copies of a string
enru