new Intl.Segmenter(locales, options) builds a splitter for text. Set granularity to "grapheme", "word" or "sentence", then call segment(text) and iterate the segments.
Grapheme mode counts user-perceived characters (important for emoji). Word mode includes an isWordLike flag so you can skip spaces.
Remember
new Intl.Segmenter(locales, { granularity })
[...segmenter.segment(text)]
granularity: "grapheme" | "word" | "sentence"
segment.isWordLike → true for real words
Syntax
Create a Segmenter, call segment, then spread into an array.
JavaScript
const seg = new Intl.Segmenter("en", { granularity: "grapheme" });
console.log([...seg.segment("A😀B")].length);
The Try It page first checks that Intl.Segmenter exists, because it is new in ES2022. In an older browser it prints a short explanation and the output above. In current browsers it runs the code for real.
How It Works
Grapheme mode. Splits by what a reader sees as one character.
Emoji stays whole. The smile is one part, not several code units.
Three pieces. A, the emoji, and B.
Example 2 — Word Segments and isWordLike
Word mode returns words and spaces. Use isWordLike to tell them apart.
JavaScript
const seg = new Intl.Segmenter("en", { granularity: "word" });
const parts = [...seg.segment("Hi there")].map(function (s) {
return s.segment + ":" + (!!s.isWordLike);
});
console.log(parts.join(","));
The Try It page first checks that Intl.Segmenter exists, because it is new in ES2022. In an older browser it prints a short explanation and the output above. In current browsers it runs the code for real.
How It Works
Words and gaps. The space is also a segment.
isWordLike. True for Hi and there, false for the space.
Filter when needed. Keep only segments where isWordLike is true.
Example 3 — Split into Sentences
Sentence mode finds sentence boundaries for a locale.
JavaScript
const seg = new Intl.Segmenter("en", { granularity: "sentence" });
const parts = [...seg.segment("Hi. Bye!")].map(function (s) {
return s.segment.trim();
});
console.log(parts.join("|"));
The Try It page first checks that Intl.Segmenter exists, because it is new in ES2022. In an older browser it prints a short explanation and the output above. In current browsers it runs the code for real.
trim for display. Removes leftover whitespace so the console line stays tidy.
Two sentences. Hi. and Bye! become separate parts.
Compatibility
Browser & Runtime Support
Intl.Segmenter is part of ES2022. Chrome, Safari and Node shipped it early; Firefox only added it in version 125, so older Firefox still needs a guard.
✓ ES2022 · Check Firefox
Intl.Segmenter
Supported in Chrome 87+, Edge 87+, Firefox 125+, Safari 14.1+, Opera 73+ and Node.js 16+. Firefox support arrived much later than Chrome and Safari.
ES2022Standard since
Google Chrome87+ · Desktop & Mobile
Full support
Microsoft Edge87+ · Chromium based
Full support
Mozilla Firefox125+ · Desktop & Mobile
Full support (late)
Apple Safari14.1+ · macOS & iOS
Full support
Opera73+ · Chromium based
Full support
Samsung InternetRecent versions · Android
Supported
Android WebView87+ · Chromium based
Supported
Node.js16+ · Server runtime
Supported
DenoSupported · JavaScript runtime
Supported
BunSupported · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
Intl.SegmenterGood (Firefox late)
Bottom line: Always feature-detect: typeof Intl.Segmenter === "function". Older Firefox (before 125) will fail without a fallback.
Frequently Asked Questions
It splits a string into graphemes, words or sentences using locale-aware rules.
Emoji and some accented characters use multiple code units. Grapheme segmentation counts what users see.
On word segments, it is true for word-like pieces and false for spaces and many separators.
Yes, but only from Firefox 125 onward. Older Firefox needs a guard or fallback.
Call segmenter.segment(text) and spread or for-of over the result. Each item has a segment string.