CancelImage Upload

How to join individual array elements in JavaScript

Joining array elements in JavaScript, is while slightly different to most programming languages, not that difficult. Indeed, all that needs to be done is specify the function join at the end of the array variable, and defining what characters the individual array elements should be joined together with:

var arrayTogether = arrayIndividual.join(", ");

Here is a more complete example, with the joined array being displayed in a html document via the JavaScript function getElementById():

<title>How to join individual array elements in JavaScript</title>
<script language="JavaScript">

function joinFoods()

      var foodsIndividual = new Array('Apples', 'Nuts', 'Oranges', 'Hamburgers');

      var foodsTogether = foodsIndividual.join(", ");

      document.getElementById("result").innerHTML = foodsTogether;


<body onload="javascript:joinFoods();">

<span id="result"></span>


Want to leave a comment?

No problem. Just enter your email and password below.

register | home | reminder

myDesignTool Networking •