Function words

  • Splits string into an array of its words.

    Parameters

    • Optionalstring: string

      The string to inspect.

    • Optionalpattern: string | RegExp

      The pattern to match words.

    Returns string[]

    Returns the words of string.

    3.0.0

    words('fred, barney, & pebbles')
    // => ['fred', 'barney', 'pebbles']

    words('fred, barney, & pebbles', /[^, ]+/g)
    // => ['fred', 'barney', '&', 'pebbles']