JS Utils Kit - v0.5.1
    Preparing search index...

    Function splitString

    • Splits a string into an array of substrings using a given delimiter.

      Parameters

      • str: string

        The input string to split.

      • val: string | RegExp = ...

        The delimiter (string or RegExp)

        whitespace /\s+/

      Returns string[]

      An array of substrings.

      • Defaults to splitting by whitespace using /\s+/.
      • Does not trim leading/trailing spaces unless explicitly passed.
      • Leading/trailing delimiters may produce empty strings.
      • With /\s+/ specifically, consecutive whitespace is collapsed (no interior empty tokens).
      splitString("a b  c");      // ["a", "b", "c"]
      splitString("a,b,c", ","); // ["a", "b", "c"]
      splitString("a1b2c3", /\d/); // ["a", "b", "c", ""]