JavaScript toString() Method: Array Object
Description
The toString() method is used to convert an array and its elements separated by commas to a string.
Version
Implemented in JavaScript 1.1
Syntax
toString()
Parameters
None.
Example:
In the following web document toString() method returns all the array elements to a string.
HTML Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8" />
<title>JavaScript toString() method example</title>
<style type="text/css">
h1 {color:red}
</style>
</head>
<body>
<h1>JavaScript : tostring() method</h1>
<hr>
<script src="array-tostring-example1.js"></script>
</body>
</html>
JS Code
var reExp = RegExp("fox");
var newParagraph = document.createElement("p");
var newText = document.createTextNode(reExp.toString());
newParagraph.appendChild(newText);
document.body.appendChild(newParagraph);
View the example in the browser
Practice the example online
See the Pen javascript-common-editor by w3resource (@w3resource) on CodePen.
See also:
JavaScript Core objects, methods, properties.
Previous: JavaScript toSource() Method: Array Object
Next: JavaScript unshift() Method: Array Object
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/javascript/object-property-method/array-tostring.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics