JavaScript typedArray.toString() with Examples
The Javascript typedArray.toString() is an inbuilt function in JavaScript that is used to convert the contents of the tyepdArray into a string.
Syntax:
typedarray.toString()
Parameters: This function does not accept any parameter.
Return value: It returns a string that represents the elements of the typedArray.
JavaScript examples to show the working of this function:
Example 1: In this example, we will convert an array of integer values to a string using typedarray.toString() function.
javascript
<script> // Constructing a new typedArray Uint8Array() object const A = new Uint8Array([5, 10, 15, 20, 25, 30, 35]); // Converting the elements of typedArray // object into string const B = A.toString(); // Printing converted string console.log(B); </script> |
Output:
5,10,15,20,25,30,35
Example 2: Here output is zero because content of the typedArray should be number not string.
javascript
<script> // Constructing a new typedArray Uint8Array() object const A = new Uint8Array([ "gfg" , "CSE" , "w3wiki" ]); // Converting the elements of typedArray // object into string const B = A.toString(); // Printing converted string console.log(B); </script> |
Output:
0,0,0