Open In App

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

Return Type: An Intl.ListFormat object



Below examples illustrate the JavaScript Intl ListFormat() Constructor:

Example 1: This example creates a conjunction ListFormat.




var courses = ["DSA", "Web Dev", "Python", "Java"]
  
console.log(new Intl.ListFormat("en-GB", { 
    style: "narrow", type: "conjunction" 
      
}).format(
    courses,
),)
  
console.log(new Intl.ListFormat("en-GB", { 
    style: "long", type: "conjunction" 
      
}).format(
    courses,
),)

Output:

DSA, Web Dev, Python, Java
DSA, Web Dev, Python and Java

Example 2: This example creates a disjunction and unit ListFormat




var courses = ["DSA", "Web Dev", "Python", "Java"]
  
console.log(new Intl.ListFormat("en-GB", { 
    style: "narrow", type: "unit" 
      
}).format(
    courses,
),)
  
console.log(new Intl.ListFormat("en-GB", { 
    style: "long", type: "disjunction" 
      
}).format(
    courses,
),)

Output:

DSA Web Dev Python Java
DSA, Web Dev, Python or Java

Supported Browsers:

We have a complete list of JavaScript Intl methods to check please go through, the JavaScript Intl Reference article


Article Tags :