Skip to content

words

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

string 拆分为其单词的数组。

¥Splits string into an array of its words.

新增于

¥Since

3.0.0

参数

¥Arguments

  1. [string=''] (字符串):要检查的字符串。

    ¥[string=''] (string): The string to inspect.

  2. [pattern] (正则表达式|字符串):要匹配单词的模式。

    ¥[pattern] (RegExp|string): The pattern to match words.

返回

¥Returns

(数组):返回 string 的单词。

¥(Array): Returns the words of string.

示例

¥Example

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

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

Lodash v4.17 中文网 - 粤ICP备13048890号