Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptJavaScript typedArray.toLocaleString() Method

JavaScript typedArray.toLocaleString() Method

The typedArray.toLocaleString() method is used to convert the elements to strings of an array. The elements converted to strings are separated by a comma (‘ , ‘). This method follows the same algorithm as of the Array.prototype.toLocaleString() and if the elements are numbers then it follows the same algorithm as Number.prototype.toLocaleString().

Syntax:

typedarray.toLocaleString( locales, options );

Parameters: This method accepts two parameters as mentioned above and described below:

  • locales: This parameter holds the value of the locale.
  • options: It is an optional parameter.

Return value: This method returns a string that represents the element of the typedArray. 

The below examples illustrate the typedArray.toLocaleString() method in JavaScript: 

Example 1: In this example, we will convert the elements of the array into string values using the typedArray.toLocaleString() method in JavaScript.

javascript




<script>
    var geek = new Uint32Array([100, 897, 123, 132, 22]);
     
    console.log(geek.toLocaleString());
     
    console.log(geek.toLocaleString('en-US'));
     
    console.log(geek.toLocaleString('hi',
        { style: 'currency', currency: 'HIR' }));
</script>


Output:

"100, 897, 123, 132, 22"
"100, 897, 123, 132, 22"
"HIR 100.00, HIR 897.00, HIR 123.00, HIR 132.00, HIR 22.00"

Example 2: In this example, we will convert the elements of the array into string values using the typedArray.toLocaleString() method in JavaScript.

javascript




<script>
    var A = " neveropen ";
    var B = " JavaScript ";
    var C = " Array.prototype.toLocaleString() ";
    var D = [A, B, C];
    var result= D.toLocaleString();
    console.log(result);
</script>


Output:

 " neveropen, JavaScript, Array.prototype.toLocaleString() "

Supported Browsers: The browsers supported by typedArray.toLocaleString() method are listed below:

  • Google Chrome
  • Firefox
  • IE
  • Opera
  • Safari
  • Edge
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments