Convert Array to String
Joins elements of a primitive array or extracts and joins nested object fields into a single string.
convertArrayToString
Joins elements of an array of primitive values or array of objects into a single string using a custom separator.
Function Signatures
function convertArrayToString<T extends Primitive>(
array: T[] | undefined,
options?: {
separator?: string;
}
): string;Parameters
| Parameter | Type | Description |
|---|---|---|
array | T[] | undefined | The array of primitives or objects to convert. |
options.separator | string (optional) | The character or string used to separate values. Defaults to ", ". |
options.target | string | Required for object arrays. The dot-notation path to the primitive property to extract. |
Returns
string: The joined string, or""if the array is empty or undefined.
Example Usage
playground.ts
Behavior Details
- Safe Handling: If the input is not a valid array, is
undefined, or is empty, the function returns""instead of throwing. - Deep Target Resolution: For arrays of objects, the target path is resolved recursively using dot-notation. TypeScript guarantees compilation checks that the target path resolves to a primitive type (such as
string,number, orboolean).
Aliases
This function can also be imported under the following name:
| Alias | Import Path |
|---|---|
joinArrayElements | toolbox-x |
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
