Skip to content

join() function

将给定 iterable 中的所有元素用分隔符连接成字符串。

Signature:

typescript
declare function join<A extends readonly []>(sep: string, iterable: A): "";

Example

ts
const joined = join('~', ['a', 'b', 'c']); // 'a~b~c'

// with pipe
pipe(
 [1, 2, 3, 4],
 map(a => a + 10),
 filter(a => a % 2 === 0)
 join('-'),
); // '12-14'

await pipe(
 Promise.resolve([1, 2, 3, 4]),
 join('-'),
); // '1-2-3-4'

// with toAsync
await pipe(
 [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3), Promise.resolve(4)],
 toAsync,
 join('-'),
); // '1-2-3-4'

Open Source Code

Released under the Apache-2.0 License.