Open In App

JavaScript Intl ListFormat() Constructor

Last Updated : 11 Apr, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

  • loc: It is a String or an array of Strings that contains the general form and interpretation of arguments
  • opt: It is an object which contains properties like localeMatcher, type, style, etc.

Return Type: An Intl.ListFormat object

Below examples illustrate the JavaScript Intl ListFormat() Constructor:

Example 1: This example creates a conjunction ListFormat.

Javascript




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

Javascript




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:

  • Chrome
  • Edge
  • Firefox
  • Opera
  • Safari

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads