JavaScript | typedArray.toLocaleString() Method

The typedArray.toLocaleString() method is used to convert the elements to strings and are separated by a locale-specific string.

Syntax:

typedarray.toLocaleString( locales, options );

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

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

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

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



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

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' }));

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

var A = " GeeksforGeeks ";  
var B = " JavaScript ";
var C = " Array.prototype.toLocaleString() ";
var D = [A, B, C];   
var result= D.toLocaleString();   
console.log(result);  

chevron_right


Output:

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

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

  • Google Chrome
  • Firefox
  • IE
  • Opera
  • Safari
  • Edge

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.