How to use arr.join() Method In Javascript
This method 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 a comma(,).
Syntax:
array.join(separator)
Example: In this case, we use an empty separator i.e. array.join(“”) to join the array elements.
let str = ["Welcome", "Geeks", "for", "Geeks"];
console.log("Joined String: " + str.join(""));
Output
Joined String: Welcomew3wiki
How to create a string by joining the elements of an array in JavaScript ?
Given an array containing array elements and here we will join all the array elements to make a single string. To join the array elements we use arr.join() method.
There are two methods by which we can create a string by joining the elements of an array:
Table of Content
- Using arr.join() Method
- Using arr.toString() Method
- Using for loop