Function words

  • Splits string into an array of its words.

    Parameters

    • string: string

      The string to inspect.

    • pattern: string | RegExp = undefined

      The pattern to match words.

    Returns string[]

    Returns the words of string.

    Since

    5.12.0

    Example

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

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