Intl

Intl.Segmenter

Creates an Intl.Segmenter object that enables locale-sensitive text segmentation into graphemes, words, or sentences

Syntax

JavaScript
new Intl.Segmenter(locales?, options?)

Parameters

ParameterTypeDescription
localesstring | string[]A BCP 47 language tag or array of tags
optionsIntl.SegmenterOptionsOptions: granularity (grapheme, word, sentence)

Return Value

An Intl.Segmenter object with a segment() method

Examples

Basic Usage
const segmenter = new Intl.Segmenter('en', { granularity: 'word' })
const segments = segmenter.segment('Hello, world!')
const words = [...segments].filter(s => s.isWordLike).map(s => s.segment)
console.log(words) // ['Hello', 'world']
Practical Example
const segmenter = new Intl.Segmenter('en', { granularity: 'sentence' })
const text = 'First sentence. Second sentence! Third?'
const sentences = [...segmenter.segment(text)].map(s => s.segment)
console.log(sentences)
Advanced Usage
const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' })
const emoji = '๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ'
const graphemes = [...segmenter.segment(emoji)].map(s => s.segment)
console.log(graphemes.length) // 1

Understanding Intl.Segmenter

The Intl.Segmenter method in JavaScript creates an Intl.Segmenter object that enables locale-sensitive text segmentation into graphemes, words, or sentences. It belongs to the Intl object and is one of the most widely used methods for working with intl values in modern JavaScript and TypeScript applications.

The method signature is new Intl.Segmenter(locales?, options?). It accepts 2 parameters: locales, options. When called, it returns an intl.segmenter object with a segment() method. Understanding when and how to use Segmenter() helps you write more expressive, readable code.

Common use cases for Intl.Segmenter include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like intl-collator, intl-numberformat, intl-listformat, enabling you to chain operations together for complex data manipulation pipelines.

Supported in Chrome 87+, Firefox 125+, Safari 15.4+, Edge 87+. Node.js 16+.

Browser Compatibility

Supported in Chrome 87+, Firefox 125+, Safari 15.4+, Edge 87+. Node.js 16+.

Related Methods

More Intl Methods

Other methods in the Intl object

Related Tools

More Intl Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.