Splitting a string

You can split a string into an array with the split function.

The first argument to split is the character to split by.

Loading TypeScript...

The second argument to split allows you to limit the number of split elements that are returned. This is an easy way to efficiently return the first few words or lines from a long string.

Loading TypeScript...

Was this page helpful?