function joinToString
joinToString<T>(): stringTransforms 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.
Examples
Example 1
Example 1
import { joinToString } from "@std/collections/join_to_string"; import { assertEquals } from "@std/assert/assert_equals"; const users = [ { name: "Kim" }, { name: "Anna" }, { name: "Tim" }, ]; const message = joinToString(users, (it) => it.name, { suffix: " are winners", prefix: "result: ", separator: " and ", limit: 1, truncated: "others", }); assertEquals(message, "result: Kim and others are winners");
Type Parameters
T