JavaScript | typedArray.join() with Example

The typedArray.join() is an inbuilt function in JavaScript which is used to join all the elements of the given typedArray into a string.
Syntax:

typedArray.join(separator);

Parameters: It accepts a parameter “separator” which is used to separate each element of the typedArray. It is optional and its default value is comma (‘,’).

Return value: It returns a string containing all the joined elements.
JavaScript code to show the working of this function:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
  // Creating some typedArrays
  const A = new Uint8Array([1, 2, 3, 4, 5]);
  const B = new Uint8Array([5, 10, 15, 20]);
  const C = new Uint8Array([0, 2, 4, 6, ,8, 10]);
  const D = new Uint8Array([1, 3, 5, 7, 9]);
   
   // Calling join() function
   a = A.join()
   b = B.join('/')
   c = C.join('+')
   d = D.join('&')
   
   // Printing new strings with joined elements
   document.write(a +"<br>");
   document.write(b +"<br>");
   document.write(c +"<br>");
   document.write(d);
      
</script>

chevron_right


Output:

1,2,3,4,5
5/10/15/20
0+2+4+6+0+8+10
1&3&5&7&9


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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.