words source npm

_.words([string=''], [pattern])

拆分字符串中的词为数组

参数

  1. [string=''] (string)

    要处理的字符串

  2. [pattern] (RegExp|string)

    匹配模式

返回值 (Array)

然后拆分后的数组

示例

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

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