Toolbox-XToolbox-X

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

ParameterTypeDescription
arrayT[] | undefinedThe array of primitives or objects to convert.
options.separatorstring (optional)The character or string used to separate values. Defaults to ", ".
options.targetstringRequired 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, or boolean).

Aliases

This function can also be imported under the following name:

AliasImport Path
joinArrayElementstoolbox-x

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page