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"