Skip to main content
Go to Latest
function joinToString
import { joinToString } from "";

Transforms the elements in the given array to strings using the given selector. Joins the produced strings into one using the given separator and applying the given prefix and suffix to the whole string afterwards. If the array could be huge, you can specify a non-negative value of limit, in which case only the first limit elements will be appended, followed by the truncated string. Returns the resulting string.


import { joinToString } from "";
import { assertEquals } from "";

const users = [
  { name: "Kim" },
  { name: "Anna" },
  { name: "Tim" },

 const message = joinToString(users, (it) =>, {
  suffix: " are winners",
  prefix: "result: ",
  separator: " and ",
  limit: 1,
  truncated: "others",

assertEquals(message, "result: Kim and others are winners");


array: readonly T[]
selector: (el: T) => string
unnamed 2: Readonly<JoinToStringOptions> = [UNSUPPORTED]