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(
"๐Ÿ‘,๐Ÿ˜€,๐Ÿ™‡โ€โ™‚๏ธ,๐Ÿคฉ,๐ŸŽ‰",
split(',')
); // ["๐Ÿ‘", "๐Ÿ˜€", "๐Ÿ™‡โ€โ™‚๏ธ", "๐Ÿคฉ", "๐ŸŽ‰"]

see pipe