JavaScript String length property

Definition and usage

length The property returns the length of the string.

The length property of an empty string is 0.

Example

let text = "Hello World!";
let length = text.length;

Try it yourself

Syntax

string.length

Return value

Type Description
Number The length of the string.

Description

String.length The property is a read-only property. It declares the length of the specified string string the number of characters in it.

For any string sThe last character index of its last character is s.length-1. It is not possible to enumerate the characters of a string using fon/in loops: length properties, using delete operators cannot delete it.

browser support

length It is an ECMAScript1 (ES1) feature.

All web browsers fully support ES1 (JavaScript 1997):

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Stöd Stöd Stöd Stöd Stöd Stöd

Relaterade sidor

JavaScript sträng

JavaScript strängmetoder

JavaScript strängsökning