Counting Words with Intl.Segmenter
Briefly

The Intl.Segmenter object provides locale-sensitive text segmentation, enabling extraction of meaningful text items such as graphemes, words, or sentences from a string.
Using String.prototype.split(' '), would fail with languages that don’t use whitespaces between words, like Japanese, Chinese, Thai, etc., making Segmenter crucial.
To use the Segmenter for counting words, create an instance with Intl.Segmenter(navigator.language, { granularity: 'word' }) and segment the input text.
The example illustrates how easily you can create an array from the words obtained through the Segmenter, showing its simplicity and utility.
Read at Raymondcamden
[
|
]