Skip to main content

split

split() function

Splits string by separator.

Signature:
declare function split(sep: string, iterable: Iterable<string>): IterableIterator<string>;

declare function split(sep: string, iterable: AsyncIterable<string>): AsyncIterableIterator<string>;

declare function split<A extends Iterable<string> | AsyncIterable<string>>(sep: string): (iterable: A) => ReturnIterableIteratorType<A, string>;

Example

const iter = split(',', '1,2,3,4');
iter.next(); // 1
iter.next(); // 2
iter.next(); // 3
iter.next(); // 4
iter.next(); // undefined

// with pipe
pipe(
"1,2,3,4,5",
split(','),
toArray,
); // ["1", "2", "3", "4", "5"]

see pipe, toArray

Open Source Code