Standard built-ins

Intl.ListFormat.prototype.formatToParts()

Try the free JavaScript compiler

Return element and literal parts for an iterable of strings.

Formal Syntax & Structure

javascript syntaxjavascript
formatter.formatToParts([list])

Parameters & Attributes

NameTypeDescription
listIterable<String>Strings in display order.

Return Value

Array

Labeled list pieces.

Working Example

Example Snippetjavascript
console.log(new Intl.ListFormat("en-US").formatToParts(["x","y"]).filter(p=>p.type==="element").length);
JavaScript Reference