The Intl.ListFormat.prototype.format() method is an inbuilt method in JavaScript which returns a string with a language-specific representation of the list.
Syntax:
listFormat.format([list]);
Parameters: This method accepts single parameter as mentioned above and described below:
- list: This parameter holds an iterable object, such as an Array.
Return Value: This method returns a language-specific formatted string representing the elements of the list.
Below examples illustrate the Intl.ListFormat.prototype.format() method in JavaScript:
Example 1:
<script> const gfg = [ 'Geeks1' , 'Geeks2' , 'Geeks3' , 'Geeks4' ]; const result1 = new Intl.ListFormat( 'en' , { style: 'long' , type: 'conjunction' }); console.log(result1.format(gfg)); const result2 = new Intl.ListFormat( 'db' , { style: 'short' , type: 'disjunction' }); console.log(result2.format(gfg)); const result3 = new Intl.ListFormat( 'en' , { style: 'narrow' , type: 'unit' }); console.log(result3.format(gfg)); </script> |
Output:
"Geeks1, Geeks2, Geeks3, and Geeks4" "Geeks1, Geeks2, Geeks3, or Geeks4" "Geeks1 Geeks2 Geeks3 Geeks4"
Example 2:
<script> const gfg = [ 'Geeks1' , 'Geeks2' , 'Geeks3' , 'Geeks4' ]; const result1 = new Intl.ListFormat( 'hi' , { style: 'long' , type: 'conjunction' }); console.log(result1.format(gfg)); const result2 = new Intl.ListFormat( 'hi' , { style: 'short' , type: 'disjunction' }); console.log(result2.format(gfg)); const result3 = new Intl.ListFormat( 'hi' , { style: 'narrow' , type: 'unit' }); console.log(result3.format(gfg)); </script> |
Output:
Supported Browsers: The browsers supported by Intl.ListFormat.prototype.format() method are listed below:
- Google Chrome
- Opera