Skip to content

join

The join() method concatenates the elements of an array of strings, inserting a separator between each of them. It respects the structure of tuples to statically compute the resulting string.

Interactive example

Syntax

Classic signature

typescript
function join<
	GenericInput extends readonly string[], 
	GenericSeparator extends string
>(
	input: GenericInput,
	separator: GenericSeparator
): GenericInput extends AnyTuple ? ComputeResult<GenericInput, GenericSeparator> : string

Curried signature

typescript
function join<
	GenericInput extends readonly string[], 
	GenericSeparator extends string
>(
	separator: GenericSeparator
): (
	input: GenericInput
) => GenericInput extends AnyTuple ? ComputeResult<GenericInput, GenericSeparator> : string

Parameters

  • input: The array (or tuple) of strings to concatenate.
  • separator: The string inserted between each element.

Return value

A string containing all elements separated by separator. When the input is a tuple, the result is known statically (ComputeResult).

See also

  • reduce - Aggregates an array with a free state
  • group - Groups multiple values by key

Sources

Released under the MIT license.