String
- String
Intl.Segmenter (the other way to split an string)
const segmenterDe = new Intl.Segmenter('de', {
granularity: 'sentence'
});
const segmentsDe = segmenterDe.segment('Was geht ab?');
// ----
// Access the segments via array spreading
console.log([...segmentsDe]);
// [
// { segment: 'Was geht ab?', index: 0, input: 'Was geht ab?' }
// ]
// ----
// Access the segments via Array.from
console.log(Array.from(segmentsDe));
// [
// { segment: 'Was geht ab?', index: 0, input: 'Was geht ab?' }
// ]
// ----
// Access the segments via for...of
for (let segment of segmentsDe) {
console.log(segment);
}
// { segment: 'Was geht ab?', index: 0, input: 'Was geht ab?' }