Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
let segmenter = new Intl.Segmenter("zh-CN", {granularity: "word"});
let input = "Intl.Segementer API 是浏览器原生的分词 API。";
let segments = segmenter.segment(input);
for (let {segment, index, isWordLike} of segments) {
  console.log("字符串位置 [%d, %d): %s%s",
    index, index + segment.length,
    segment,
    isWordLike ? " [单词]" : ""
  );
}
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers