/

HTML / CSS / JavaScript Tutorial

JavaScript Array method: join()

[this page | pdf | back links]

The join() method (when applied to a JavaScript array) joins all elements of an array into a string.

 

It has the following syntax with the following parameters. It returns a string as above.

 

array.join(delimiter)

 

Parameter

Required / Optional

Description

delimiter

Optional

The delimiter (i.e. separator) inserted between consecutive element strings. Default is a comma, i.e. “,”

 

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 = ["a","b","c","d"];
document.getElementById("Example").innerHTML =
  'var h = ["a","b","c","d"];<br>' +
  'var x = h.join("&");';
document.getElementById("Result").innerHTML = h.join("&");
</script>

</body>
</html>

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


NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays


Desktop view | Switch to Mobile