JavaScript (ES2026) reference · String Methods
JavaScript String length Property
The number of UTF-16 code units in the string, which is more than the number of characters for emoji.
JavaScript (ES2026) Since ES1
Syntax
string.length
Return value
A non-negative integer.
Examples
console.log("camel".length, "".length, "\u{1F42B}".length);
Output
5 0 2
const text = "hi \u{1F42B}";
console.log(text.length, [...text].length); // code units vs characters
Output
5 4
Version history
| Version | Change |
|---|---|
| JavaScript ES1 | Added |
In other languages
len()· Pythonstrlen()· PHPmb_strlen()· PHP
Related
string.at()· Return the character at an index, where negative indexes count from the end: str.at(-1) is the last character.string.split()· Split a string into an array of substrings at each separator (a string or regex), with an optional limit.array.length· The number of elements in the array. Setting it shortens or extends the array.- JavaScript Strings · tutorial
- JavaScript String Methods · tutorial