/

HTML / CSS / JavaScript Tutorial

JavaScript Array method: toString()

[this page | pdf | back links]

The toString() method (when applied to a JavaScript array) returns the string value of the array, with the elements being delimited (separated) by commas.

 

It has the following syntax (with no parameters):

 

array.toString()

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var h = [-1, 2, 3];
document.getElementById("Example").innerHTML =
  'var h = [-1, 2, 3];<br>' +
  'var x = h.toString();';
document.getElementById("Result").innerHTML = h.toString();
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodArrayToString() {
  var h = [1, 2, 3]; return !!h.toString;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays


Desktop view | Switch to Mobile