String.split
split($stringOrRegex, $options={}) -> list
Description
Split into a list of substrings, on a string delimiter or regex pattern.
All elements will be trimmed of whitespace, and empty strings will be filtered out.
'a / b / c'.split('/') //= ['a', 'b', 'c'] '/a/b/c/ /'.split('/') //= ['a', 'b', 'c'] 'a b c '.split(rx'\s+') //= ['a', 'b', 'c']
Options
Option | Value | Description |
---|---|---|
limit |
number | Maximum number of returned elements. The last element will contain the rest of the string. |
keepWhitespace |
true/false | Do not automatically trim and filter empty elements. |
'a/b/c/d/e'.split('/', { limit: 3 }) //= ['a', 'b', 'c/d/e'] '/a/b/ c / '.split('/', 0, -keepWhitespace) //= ['', 'a', 'b', ' c ', ' ']