The join() Method

The join() method also joins all array elements into a string. It behaves just like toString(), but in addition you can specify the separator that joins the elements of the array:

HTML file: Displayed by browser:
<body>

<h4>The join() method joins array elements into a string:</h4>
<p id="demo"></p>
<p id="demo1"></p>

<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.join(" * ");
document.getElementById("demo1").innerHTML = fruits.join(" & ");
</script>

</body>

The join() method joins array elements into a string:


BackTable of ContentsNext