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 = " zambiatek ";Â Â Â Â var B = " JavaScript ";Â Â Â Â var C = " Array.prototype.toLocaleString() ";Â Â Â Â var D = [A, B, C];Â Â Â Â var result= D.toLocaleString();Â Â Â Â console.log(result);</script> |
Output:
" zambiatek, JavaScript, Array.prototype.toLocaleString() "
Supported Browsers: The browsers supported by typedArray.toLocaleString() method are listed below:
- Google Chrome
- Firefox
- IE
- Opera
- Safari
- Edge



