JavaScript & jQuery Tutorials

JS Home Right Arrow JS Reference Right Arrow Array Right Arrow join()

join()  Array  instance method

Description

Creates a string from the elements within an array.

Syntax


Signature Description
anArray.join(separator)Creates a string from the elements within an array.

Parameters


Parameter Description
separatorConverted to a string, if required and used to seperate the elements of the array.
Default value is a comma symbol.

Examples

The code below creates some strings with delimiters.



// Create an array of weekdays.
var weekDays = ['Mon', 'Tues', 'Wed', 'Thurs'];

// Default delimiter - aVariable = 'Mon,Tues,Wed,Thurs' after join below.
var aVariable = weekDays.join(); 

// ' , ' delimiter - bVariable = 'Mon , Tues , Wed , Thurs' after join below.
var bVariable = weekDays.join(' , '); 

// '/' delimiter - cVariable = 'Mon/Tues/Wed/Thurs' after join below.
var cVariable = weekDays.join('/');
alert(aVariable + ' - ' + bVariable + ' - ' + cVariable); 

Press the button below to action the above code:



Related Tutorials

JavaScript Intermediate Tutorials - Lesson 1 - Arrays




  

go to home page Homepage go to top of page Top