join ExamplesΒΆ

The general syntax for this method is:

arrayName.join('connector')

join combines all the elements of an array into a string. The connector determines the string that "glues" the array elements together.

Example

 1let arr = [1, 2, 3, 4];
 2let words = ['hello', 'world', '!'];
 3let newString = '';
 4
 5newString = arr.join("+");
 6console.log(newString);
 7
 8newString = words.join("");
 9console.log(newString);
10
11newString = words.join("_");
12console.log(newString);

Output

1+2+3+4
helloworld!
hello_world_!