Favorites

JavaScript String.prototype.length Property

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
String.prototype.length
JavaScript String Instance propertyThis property is supported by all modern browsers.
Updated 28th November 2026

The length property gives the number of characters in a string, counted as UTF-16 code units, so some emoji count as two.

Description

The length property of a String value contains the length of the string in UTF-16 code units. For everyday text this is the number of characters, but characters outside the Basic Multilingual Plane, such as many emoji, use two code units, and combined emoji can use many more.

To count what users see as characters, use [...str].length for code points, or Intl.Segmenter for grapheme clusters. length is read-only; assigning to it has no effect.

Because strings are immutable, length can't be used to shorten a string the way it can for arrays; use slice() instead. It's commonly used to check input, such as if (password.length < 8), and to loop over characters by index, although for...of handles emoji and other multi-unit characters correctly.

Syntax

string.length

Value

A non-negative integer: the number of UTF-16 code units in the string.

Example

console.log('hello'.length);
console.log(''.length);
console.log('😀'.length);
console.log([...'😀'].length);

Browser Support

The following information will show you the current browser support for the String.prototype.length property. Hover over a browser icon to see the version that first introduced support for this property.

This property is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee