JavaScript | Array.join() Method
Introduction:
The array.join() method is an inbuilt function in JavaScript which is used to join the elements of an array into a string.The elements of the string will be separated by a specified separator and its default value is comma(, ).
Syntax:
array.join(separator)
- separator: It is Optional i.e, it can be either used as parameter or not.Its default value is comma(, ).
- It returns the String which contain the collection of array’s elements.
- ECMAScript 1
- Here 2nd column contained int values are verson of the corresponding browser.
Feature Basic support Chrome 1 Edge Yes Firefox 1 Internet Explorer 5.5 Opera Yes Safari Yes Android webview Yes Chrome for Android Yes Edge mobile Yes Firefox for Android 4 Opera Android Yes iOS Safari Yes
Parameters:
Return Value:
JavaScript Version:
Browser Support:
Examples:
Input: elements = [\'geeksforgeeks\', \'gfg\'] Output: \"geeksforgeeks, gfg\"
Explanation:
Here input contains some elements as an array. And output becomes the string of elements of the array.
This is done with the help of Array.join() method in JavaScript.
Let\’s see JavaScript program:
// input array contains some elements to be joined. var elements = [\'geeksforgeeks\', \'gfg\']; // Here join() function joins the elements of the array. console.log(elements.join()); // Here output elements are seperated by dot (.). console.log(elements.join(\'.\')); // Here output elements are seperated by hyphen (-). console.log(elements.join(\'-\')); |
Output:
> \"geeksforgeeks, gfg\" > \"geeksforgeeks.gfg\" > \"geeksforgeeks-gfg\"
- Whenever we need to get elements of any array that time we take help of Array.join() Method in JavaScript.
// input array contains some elements to be joined.varelements = [\'geeksforgeeks\', \'gfg\'];// Here output elements are seperated by addition symbol (+).console.log(elements.join(\'+\'));chevron_rightfilter_noneOutput:
> \"geeksforgeeks+gfg\"
Application:
Recommended Posts:
- JavaScript | exec() Method
- JavaScript | Array.from() method
- JavaScript | Sort() method
- JavaScript | compile() Method
- JavaScript | Array map() Method
- JavaScript | Array from() Method
- JavaScript | getTime() Method
- JavaScript | Replace() Method
- Javascript | MouseEvent getModifierState() Method
- JavaScript | Array valueOf() Method
- JavaScript | Array.findIndex() Method
- Javascript | Window confirm() Method
- JavaScript | removeEventListener() method with examples
- Javascript | Window prompt() Method
- JavaScript | RegExp toString() Method
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.



