JavaScript Intl ListFormat formatToParts() Method
Last Updated :
12 Jul, 2025
The Intl.ListFormat.prototype.formatToParts() method is an inbuilt method in JavaScript that returns an Array of objects representing the different components that can be used to format a list of values in a locale-aware fashion.
Syntax:
Intl.ListFormat.prototype.formatToParts(list)
Parameters: This method accepts a single parameter as mentioned above and described below:
- list: This parameter holds an Array of values to be formatted according to a locale.
Return Value: This method returns an Array of components that contains the formatted parts from the list.
The below examples illustrate the Intl.ListFormat.prototype.formatToParts() method in JavaScript:
Example 1: In this example, we will see the basic use of the Intl.ListFormat.prototype.formatToParts() method in JavaScript.
javascript
<script>
const gfg = ['Geeks1', 'Geeks2', 'Geeks3'];
const result = new Intl.ListFormat('en-GB',
{ style: 'long', type: 'conjunction' });
let val = result.formatToParts(gfg);
console.log(val[0]);
console.log(val[1]);
console.log(val[2]);
console.log(val[3]);
console.log(val[4]);
</script>
Output:
Object { type: "element", value: "Geeks1" }
Object { type: "literal", value: ", " }
Object { type: "element", value: "Geeks2" }
Object { type: "literal", value: " and " }
Object { type: "element", value: "Geeks3" }
Example 2: In this example, we will see the basic use of the Intl.ListFormat.prototype.formatToParts() method in JavaScript.
javascript
<script>
const gfg = ['Geeks1', 'Geeks2', 'Geeks3'];
const result = new Intl.ListFormat('hi',
{ style: 'long', type: 'conjunction' });
let val = result.formatToParts(gfg);
console.log(val[0]);
console.log(val[1]);
console.log(val[2]);
console.log(val[3]);
console.log(val[4]);
</script>
Output:
Object {type: 'element', value: 'Geeks1'}
Object {type: 'literal', value: ', '}
Object {type: 'element', value: 'Geeks2'}
Object {type: 'literal', value: ', और '}
Object {type: 'element', value: 'Geeks3'}
We have a complete list of Javascript Intl methods, to check those please go through the Javascript Intl Complete Reference article.
Supported Browsers: The browsers supported by Intl.ListFormat.prototype.formatToParts() method are listed below:
- Google Chrome 72 and above
- Edge 79 and above
- Firefox 78 and above
- Opera 60 and above
- Safari 14.1 and above
Similar Reads
JavaScript Intl ListFormat format() Method The Intl.ListFormat.prototype.format() method is an inbuilt method in JavaScript that returns a string with a language-specific representation of the list. Syntax: listFormat.format([list]); Parameters: This method accepts a single parameter as mentioned above and described below: list: This paramet
2 min read
JavaScript Intl ListFormat format() Method The Intl.ListFormat.prototype.format() method is an inbuilt method in JavaScript that returns a string with a language-specific representation of the list. Syntax: listFormat.format([list]); Parameters: This method accepts a single parameter as mentioned above and described below: list: This paramet
2 min read
JavaScript Intl ListFormat format() Method The Intl.ListFormat.prototype.format() method is an inbuilt method in JavaScript that returns a string with a language-specific representation of the list. Syntax: listFormat.format([list]); Parameters: This method accepts a single parameter as mentioned above and described below: list: This paramet
2 min read
JavaScript Intl ListFormat() Constructor JavaScript Intl.ListFormat() Constructor is used for creating Intl.ListFormat object. This constructor is created using the new keyword. If we create the constructor without the new keyword it will give a TypeError. Syntax: new Intl.ListFormat(loc, opt) Parameters: It has two parameters both are opt
2 min read
Java String format() Method In Java, the String.format() method allows us to create a formatted string using a specified format string and arguments. We can concatenate the strings using this method, and at the same time, we can format the output with options such as width, alignment, decimal places, and more.Example: In the e
4 min read
Java String format() Method In Java, the String.format() method allows us to create a formatted string using a specified format string and arguments. We can concatenate the strings using this method, and at the same time, we can format the output with options such as width, alignment, decimal places, and more.Example: In the e
4 min read