Javascript examples for Array:join
The join() method joins the array elements into a string, and returns the string.
The elements will be separated by a specified separator. The default separator is comma (,).
array.join(separator);
Parameter | Description |
---|---|
separator | Optional. The separator to be used. If omitted, the elements are separated with a comma |
A String, representing the array values, separated by the specified separator
The following code shows how to Join the elements of an array into a string:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> function myFunction() {//from w w w . j a va2s . c o m var fruits = ["a","b","c","d","e"]; var x = document.getElementById("demo"); x.innerHTML = fruits.join(" and "); } </script> </body> </html>