Skip to main content

join()

join<T>(array, separator): string

Converts all elements in array into a string separated by separator.

DEPRECATED

Use array.join(separator) directly instead.

Reason:
Native equivalent method now available


Type Parametersโ€‹

T: Tโ€‹

The type of elements in the array.


Parametersโ€‹

array: T[]โ€‹

The array to convert.

separator: string = ","โ€‹

The element separator.


Returns: stringโ€‹

The joined string.


See Alsoโ€‹


Sinceโ€‹

2.0.0


Also known asโ€‹

join (Lodash, es-toolkit, Remeda, Ramda, Effect) ยท โŒ (Radashi, Modern Dash, Antfu)


Exampleโ€‹

const numbers = [1, 2, 3, 4, 5];

// โŒ Deprecated approach
const joined = join(numbers, '-');
console.log(joined); // "1-2-3-4-5"

// โœ… Recommended approach
const joinedNative = numbers.join('-');
console.log(joinedNative); // "1-2-3-4-5"

How it works?โ€‹

Joins array elements into a string. Deprecated: Use array.join() directly.

Native Equivalentโ€‹

// โŒ join(arr, '-')
// โœ… arr.join('-')

Use Casesโ€‹

Create comma-separated string ๐Ÿ“Œโ€‹

Join array elements into a string.

const tags = ["javascript", "typescript", "nodejs"];
tags.join(", ");
// => "javascript, typescript, nodejs"

Build path from segmentsโ€‹

Combine path segments with a separator.

const segments = ["home", "user", "documents"];
segments.join("/");
// => "home/user/documents"

Format display listโ€‹

Create readable lists for display.

const names = ["Alice", "Bob", "Charlie"];
names.join(" and ");
// => "Alice and Bob and Charlie"