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"