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.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join