Segments
Baseline 2024Newly available
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
A Segments
object is an iterable collection of the segments of a text string. It is returned by a call to the segment()
method of an Intl.Segmenter
object.
Try it
const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
const string1 = "Que ma joie demeure";
const segments = segmenterFr.segment(string1);
console.log(segments.containing(5));
// Expected output:
// Object {segment: 'ma', index: 4, input: 'Que ma joie demeure', isWordLike: true}
Instance methods
Segments.prototype.containing()
-
Returns an object describing the segment in the original string that includes the code unit at a specified index.
Segments.prototype[Symbol.iterator]()
-
Returns an iterator to iterate over the segments.
Specifications
Specification |
---|
ECMAScript® 2025 Internationalization API Specification # sec-segments-objects |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Segments | ||||||||||||||
[Symbol.iterator] | ||||||||||||||
containing |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.