Convert Arrays to Strings

The strength of JavaScript arrays lies in the array methods. The JavaScript method toString() converts an array to a string of (comma separated) array values.

HTML file: Displayed by browser:
<body>

<h4>The toString() method returns an array as a comma separated string:</h4>
<p id="demo"></p>

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

</body>

The toString() method returns an array as a comma separated string:


BackTable of ContentsNext