The strSplit() splits a string into substrings using the pattern and divides a String into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

0.9.1

strSplit("Oh brave new world that has such people in it.", " ");
// [ "Oh", "brave", "new", "world", "that", "has", "such", "people", "in", "it." ]

strSplit("Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec", ",");
// [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  • Parameters

    • value: string

      The string value to be split into substrings.

    • separator: string | RegExp

      The pattern describing where each split should occur. Can be undefined, a string, or an object with a Symbol.split method (if supported) — the typical example being a regular expression. Omitting separator or passing undefined causes strSplit() to return an array with the calling string as a single element. All values that are not undefined or objects with a @@split method are coerced to strings.

    • Optionallimit: number

      A non-negative integer specifying a limit on the number of substrings to be included in the array. If provided, splits the string at each occurrence of the specified separator, but stops when limit entries have been placed in the array. Any leftover text is not included in the array at all.

      • The array may contain fewer entries than limit if the end of the string is reached before the limit is reached.
      • If limit is 0, [] is returned.

    Returns string[]

    An Array of strings, split at each point where the separator occurs in the given string.