# JOIN

**The JOIN function combines the strings within a list into a single string.**

This function takes up to two pieces of input: a list of strings and an optional separator string. It outputs a single string consisting of all strings in the list joined together, in order. If applicable, the separator string will appear between each combination, marking where each string in the given list began and ended.

#### Declaration

```javascript
JOIN(list_of_strings, separator) -> combined_string
```

&#x20;

#### Parameters

**list\_of\_strings** (required, type: _list_) A list of strings you want to join together.

There is no upper limit to how many strings can be in this list, but at least two strings are required as input in order for the JOIN function to return output that differs from this input.

**separator** (optional, type: _string_) A string to be placed in between each of the strings in **list\_of\_strings**.

#### Return Values

**combined\_string** (type: _string_) A string created by joining all of the strings in the given list, with (if applicable) the separator between each of them.

#### Examples

Below are a few examples of the JOIN function in use. This first example takes the strings in the list \["Ann", "Bob", "Carol"] and joins them into a single string.&#x20;

```javascript
JOIN(["Ann", "Bob", "Carol"]) -> "AnnBobCarol"
```

The above example did not separate the items in the given list with any other string – that is, all the strings from the list \["Ann", "Bob", "Carol"] are mashed together – because no separator was provided as input. The following example includes the separator " ", which separates the strings in the given list with a space. Note that the separator only appears between items in the given list; it does not pop up at the beginning of the string, and it does not hang off the end.

```javascript
JOIN(["Ann", "Bob", "Carol"], " ") -> "Ann Bob Carol"
```

Neither **list\_of\_strings** nor **separator** need to be hardcoded. For the last example, assume the formula has access to the following variables:

```javascript
names = ["Ann", "Bob", "Carol"]  
example_string = " and "
```

In the following example, the JOIN function combines the strings stored in the list **names** and puts the string stored in **example\_string** between them.

```javascript
JOIN(names, example_string) -> "Ann and Bob and Carol"
```

#### Discussion

JOIN can be thought of as the opposite of the [SPLIT](../text-functions/split) function. That is, for most strings and lists of strings, let's call our examples **string** and **list** respectively, you can use SPLIT to undo what JOIN did, like so:

```javascript
SPLIT(JOIN(list, string), string) -> list
```

Note, however, there are few edge cases where this doesn't work perfectly. If any of the item strings in **list** contained the value of **string** as a subcomponent, SPLIT will not perfectly undo what JOIN did. Consider the following example:

```javascript
SPLIT(JOIN(["This is", "a string"], " "), " ") -> ["This", "is", "a", "string"]
```

In the above example, the JOIN function combined the strings "This is" and "a string" by putting a space between them. But the initial two strings already contained a space, and so when the SPLIT function removed all spaces from their resulting combination and put the fragments into a list, it removed both the space added by the JOIN function and the spaces that were already part of the initial strings, resulting in list output that didn't perfectly match the list input.
