JavaScript Intl.Segmenter() Constructor

Beginner
6 min read
Updated: Nov 2026
3 examples
Constructor

Definition

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);
CallWhat it does
{ granularity: "grapheme" }Split into user-perceived characters.
{ granularity: "word" }Split into words and separators.
{ granularity: "sentence" }Split into sentences.
segment.isWordLikeTrue for word-like pieces, false for spaces.

A standard JavaScript constructor on the Intl object: create one with new Intl.Segmenter(). No import required. Guard older Firefox. Siblings: Intl.getCanonicalLocales(), Intl.supportedValuesOf(), Intl.Collator(), Intl.DateTimeFormat(), Intl.DisplayNames(), Intl.DurationFormat(), Intl.ListFormat(), Intl.Locale(), Intl.NumberFormat(), Intl.PluralRules(), Intl.RelativeTimeFormat().

Library declarations
JavaScript
// ECMAScript 2022 — Intl.Segmenter
new Intl.Segmenter(locales, options)
segmenter.segment(input)

// options.granularity: "grapheme" | "word" | "sentence"
// each segment: { segment, index, input, isWordLike? }

Parameters

ParameterDescription
localesOptional. Locale string or list, such as "en".
optionsOptional. Mainly granularity.
inputFor segment: the string to split.

Return Value

Return ValueDescription
Segmenter objectFrom the constructor.
Segments iterableFrom segment: iterate or spread to read each piece.

JavaScript Examples

Example 1 — Count Graphemes Including Emoji

A smiling emoji is one grapheme even though it uses more than one code unit.

JavaScript
const seg = new Intl.Segmenter("en", { granularity: "grapheme" });
const parts = [...seg.segment("A😀B")].map(function (s) { return s.segment; });

console.log("Count: " + parts.length);
console.log("Parts: " + parts.join("|"));
Try It Yourself

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

  1. Grapheme mode. Splits by what a reader sees as one character.
  2. Emoji stays whole. The smile is one part, not several code units.
  3. 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(","));
Try It Yourself

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

  1. Words and gaps. The space is also a segment.
  2. isWordLike. True for Hi and there, false for the space.
  3. 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("|"));
Try It Yourself

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

  1. Sentence granularity. Boundaries follow locale punctuation rules.
  2. trim for display. Removes leftover whitespace so the console line stays tidy.
  3. Two sentences. Hi. and Bye! become separate parts.

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.

ES2022 Standard since
Google Chrome 87+ · Desktop & Mobile
Full support
Microsoft Edge 87+ · Chromium based
Full support
Mozilla Firefox 125+ · Desktop & Mobile
Full support (late)
Apple Safari 14.1+ · macOS & iOS
Full support
Opera 73+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 87+ · Chromium based
Supported
Node.js 16+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
Intl.Segmenter Good (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.

Back to Intl Methods

Open the Intl methods index to browse every helper and formatter in this series.

Intl Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful