| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter | [Back] [Original] |
Get to know MDN better
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The Intl.Segmenter object enables locale-sensitive text segmentation, enabling you to get meaningful items (graphemes, words or sentences) from a string.
const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
const string = "Que ma joie demeure";
const iterator = segmenterFr.segment(string)[Symbol.iterator]();
console.log(iterator.next().value.segment);
// Expected output: 'Que'
console.log(iterator.next().value.segment);
// Expected output: ' '
Intl.Segmenter()Creates a new Intl.Segmenter object.
Intl.Segmenter.supportedLocalesOf()Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
These properties are defined on Intl.Segmenter.prototype and shared by all Intl.Segmenter instances.
Intl.Segmenter.prototype.constructorThe constructor function that created the instance object. For Intl.Segmenter instances, the initial value is the Intl.Segmenter constructor.
Intl.Segmenter.prototype[Symbol.toStringTag]The initial value of the [Symbol.toStringTag] property is the string "Intl.Segmenter". This property is used in Object.prototype.toString().
Intl.Segmenter.prototype.resolvedOptions()Returns a new object with properties reflecting the locale and granularity options computed during initialization of this Intl.Segmenter object.
Intl.Segmenter.prototype.segment()Returns a new iterable Segments instance representing the segments of a string according to the locale and granularity of this Intl.Segmenter instance.
If we were to use String.prototype.split(" ") to segment a text in words, we would not get the correct result if the locale of the text does not use whitespaces between words (which is the case for Japanese, Chinese, Thai, Lao, Khmer, Myanmar, etc.).
const str = "";
console.table(str.split(" "));
// ['']
// The two sentences are not correctly segmented.
const str = "";
const segmenterJa = new Intl.Segmenter("ja-JP", { granularity: "word" });
const segments = segmenterJa.segment(str);
console.table(Array.from(segments));
// [{segment: '', index: 0, input: '', isWordLike: true},
// etc.
// ]
| Specification |
|---|
| ECMAScript 2027 Internationalization API Specification # segmenter-objects |
This page was last modified on Jul 20, 2025 by MDN contributors.
Intl.SegmenterObject/FunctionIntlIntl.CollatorIntl.DateTimeFormatIntl.DisplayNamesIntl.DurationFormatIntl.ListFormatIntl.LocaleIntl.NumberFormatIntl.PluralRulesIntl.RelativeTimeFormatYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |