Related Articles

Related Articles

JavaScript | Intl.ListFormat.prototype.format() Method
  • Last Updated : 16 Apr, 2020

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:

"Geeks1, Geeks2, Geeks3, and Geeks4"
"Geeks1, Geeks2, Geeks3, or Geeks4"
"Geeks1 Geeks2 Geeks3 Geeks4"

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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>

chevron_right


Output:

Supported Browsers: The browsers supported by Intl.ListFormat.prototype.format() method are listed below:

  • Google Chrome
  • Opera

full-stack-img




My Personal Notes arrow_drop_up
Recommended Articles
Page :