Thursday, September 18, 2025
HomeLanguagesJavascriptJavaScript Intl Segementer() Constructor

JavaScript Intl Segementer() Constructor

JavaScript Intl Segmenter() Constructor is used for creating Intl.Segmenter object. This constructor is created using the new keyword. If we create the constructor without the new keyword it will give a TypeError.

Syntax:

new Intl.Segmenter(loc, opt)

Parameters: It has two parameters both are optional.

  • loc: It is a String or an array of Strings that contains the general form and interpretation of arguments
  • opt: It is an object which contains properties like localeMatcher and granularity.

Return Value: An Intl.Segmenter object

Below examples illustrate the JavaScript Intl Segmenter() Constructor:

Example 1: This example creates a basic segmenter object and uses it to segment a sentence

Javascript




const format = new Intl.Segmenter("en", {granularity:"word"})
  
var sen = "Welcome to neveropen";
var iter = format.segment(sen)[Symbol.iterator]();
  
for(var i = 0; i<5;i++) {
    console.log(iter.next().value)
}


Output: The blank line in the output represents the space between the words

Welcome

to
  
neveropen

Example 2: This example uses the Segmenter object to segment the sentence into individual letters.

Javascript




const format = new Intl.Segmenter("en", {granularity:"grapheme"})
  
var sen = "Geeks";
var iter = format.segment(sen)[Symbol.iterator]();
  
for(var i = 0; i<5;i++) {
    console.log(iter.next().value.segment)
}


Output:

G
e
e
k
s

Supported Browsers:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

We have a complete list of JavaScript Intl methods to check please go through, the JavaScript Intl Reference article

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32299 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6660 POSTS0 COMMENTS
Nicole Veronica
11834 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11895 POSTS0 COMMENTS
Shaida Kate Naidoo
6779 POSTS0 COMMENTS
Ted Musemwa
7052 POSTS0 COMMENTS
Thapelo Manthata
6735 POSTS0 COMMENTS
Umr Jansen
6741 POSTS0 COMMENTS