阅读(3890) (0)

Lodash _.words

2021-09-23 14:42:37 更新

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

拆分字符串string中的词为数组 。

添加版本

3.0.0

参数

  1. [string=''] (string): 要拆分的字符串。
  2. [pattern] (RegExp|string): 匹配模式。

返回

(Array): 返回拆分string后的数组。

例子

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