join()

The join method in JavaScript is utilized to concatenate all the elements of an array into a single string, resulting in a new string output. This method allows for the use of various types of separators to distinguish between the elements of the array.

Syntax

The join function is expressed using the subsequent syntax:

Example

array.join(separator)

Parameter

Separator - This parameter is not mandatory. It denotes the character that separates the elements within the array.

Return

A newly created string comprises the values from the array, separated by the designated delimiter.

JavaScript Array join method example

Let's see some examples of join method.

Example 1

Let's see a simple example of join method.

Example

<script>

var arr=["AngularJs","Node.js","JQuery"]

var result=arr.join()

document.write(result);

</script>

Output:

Output

AngularJs,Node.js,JQuery

Example 2

In this illustration, we will utilize the '-' character as a delimiter to divide the elements of the array.

Example

<script>

var arr=["AngularJs","Node.js","JQuery"]

var result=arr.join('-')

document.write(result);

</script>

Output:

Output

AngularJs-Node.js-JQuery

Input Required

This code uses input(). Please provide values below: