Skip to content

split() function

按分隔符拆分字符串。

Signature:

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

Example

ts
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

Released under the Apache-2.0 License.