JS: Join() Method

The <span style="color:#a30500" class="tadv-color">join()</span> method from string class, join the characters or words of a string.


This method is useful in some operations where we have to split the string into an array. The<span style="color:#a30500" class="tadv-color"> join()</span> will concatenate it into a string again.

The example program for join operation is given below.

<!DOCTYPE html>
   <title>JS: join() Method</title>
   <meta charset="utf-8">
var name = "woodchuck";
//split the string into a character array
var split_name = name.split('');
//join the characters together to form string
var out = split_name.join('');
//output = ['w','o','o','d','c','h','u','c','k']
//output = 'woodchuck'

The above script will join the character only, However, if you want to join words use a <span style="color:#a30000" class="tadv-color">join(' '); </span>

You must add more white space in<span style="color:#a30000" class="tadv-color"> join()</span> method. The following code will show the difference.

string = ['h','e','l','l','o','','w','o','r','l','d'];

//output = "helloworld"

string.join(' ');
//output = 'hello world'

//output = h=e=l=l=o=w=o=r=l=d


Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock