JS: String Operations

By Xah Lee. Date: . Last updated: .

String length

console.assert("abc".length === 3);

Note: no parenthesis after β€œlength”.

String length of unicode string

if the string contains emoji, see:

Substring

console.assert("01234".slice(1, 3) === "12");

Index starts at 0.

Join String

Use the plus sign + to join strings.

console.assert(("aa" + "bb") === "aabb");

String Methods

JavaScript. String