JavaScript Array toString() method : The toString() method is used to cast the array object into a string object and return that string. The elements in the string is separated by comma.
Syntax of Array toString() method :
array.toString()
Example of Array toString() method : In this example I will show, how to convert an array object to a string object.
<!DOCTYPE html>
<html>
<body>
<p>To convert the array into a String Object, click the button "convert to string" .</p>
<button onclick="convertToString()">convert to string</button>
<p id="container"></p>
<script>
function convertToString() {
var fruits = ["Karan", "Sumit", "Rahul", "Pankaj"];
fruits.toString();
document.getElementById("container").innerHTML = fruits;
}
</script>
</body>
</html>
Output :
Karan, Sumit, Rahul, Pankaj
0 Comment(s)