Back to Functions

join

arrays

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

Installation

Import
import { join } from '@tulx/utils';

Source Code

Implementation
/**
 * Converts all elements in array into a string separated by separator.
 *
 * @param array - The array to convert.
 * @param separator - The element separator.
 * @returns The joined string.
 *
 * @example
 * ```ts
 * join(['a', 'b', 'c'], '~'); // 'a~b~c'
 * ```
 */
export function join(
  array: readonly unknown[],
  separator: string = ','
): string {
  return array.join(separator);
}

Example

import { join } from '@tulx/utils';

join(['a', 'b', 'c'], '~'); // 'a~b~c'

Related Functions