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
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

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Array

Class Properties
prototype
Instance Properties
constructor
length
Class Methods
None.
Instance Methods Getters
concat()
join()
slice()
toString()
Instance Methods Setters
pop()
push()
reverse()
shift()
sort()
splice()
unshift()

Statements

Operators