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
<!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
<!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>