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