JavaScript Array.join() Method

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

The Array.join() method of JavaScript is used to join the array and return as a string.

The syntax is as follows −

array.join(separator)

Above, set the separator to be used as a parameter.

Let us now implement the Array.join() method in JavaScript minus;

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
   <h2>Demo Heading</h2>
   <p>Is this is an array?</p>
   <p id="test"></p>
   <script>
      var arr = ["Accessories", "Electronics", "Books", "Pet Supplies"];
      var res = document.getElementById("test");
      res.innerHTML = Array.isArray(arr)+" = "+arr.join()
   </script>
</body>
</html>

Output

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
   <h2>Demo Heading</h2>
   <p id="test"></p>
   <script>
      var arrStud = ["Laptop", "Desktop", "Tablet"];
      document.getElementById("test").innerHTML = "Initial array = "+arrStud+", <br>String with    seperator = "+arrStud.join("...");
   </script>
</body>
</html>

Output

raja
Published on 17-Dec-2019 13:12:08
Advertisements