What is the usage of join() method in JavaScript?

JavascriptWeb DevelopmentFront End Technology

JavaScript array join() method joins all the elements of an array into a string.

The following is the parameter −

  • separator − Specifies a string to separate each element of the array. If omitted, the array elements are separated with a comma.


You can try to run the following code to learn how to work with join() method in JavaScript −

      <title>JavaScript Array join Method</title>
         var arr = new Array("Football","Hockey","Squash");

         var str = arr.join();
         document.write("str : " + str );

         var str = arr.join(", ");
         document.write("<br />str : " + str );

         var str = arr.join(" + ");
         document.write("<br />str : " + str );
Published on 23-Feb-2018 15:54:43