Javascript Array - join method


The join() method joins the individual elements of an array - combines them into a string, and returns the string. By default, the joined elements will be separated by a a comma separator.

Take a look at the following example

<html>
<body>

<script type="text/javascript">


var cars = ["Toyota", "Honda", "Audi"];
var carstring = cars.join()

document.writeln('Popular Car brands ' + carstring + '<br />');

</script>

</body>
</html>



Try this example online here .
It is also possible to specify an alternate separator by passing the separator inside the join function. Look at the following example. Take a look at the following example

<html>
<body>

<script type="text/javascript">


var cars = ["Toyota", "Honda", "Audi"];
var carstring = cars.join();
var carstring1 = cars.join(', ');
var carstring2 = cars.join('+');

document.writeln('Popular Car brands ' + carstring + '<br />');
document.writeln('Popular Car brands ' + carstring1 + '<br />');
document.writeln('Popular Car brands ' + carstring2 + '<br />');
</script>

</body>
</html>



Try this example online here .