join()
Array
instance method
JS Home <<
JS Reference <<
Array <<
join()
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 |
---|---|
separator | Converted 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);
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 1 - Arrays