Standard built-ins

Intl.Segmenter.prototype.segment()

Try the free JavaScript compiler

Return an iterable Segments object for a string, using configured granularity. Records include UTF-16 index and segment, with word-likeness for word granularity.

Formal Syntax & Structure

javascript syntaxjavascript
formatter.segment(string)

Parameters & Attributes

NameTypeDescription
stringStringText to segment.

Return Value

Segments

Iterable segmentation result.

Working Example

Example Snippetjavascript
const s=new Intl.Segmenter("en",{granularity:"grapheme"});console.log([...s.segment("é")].length);
JavaScript Reference