> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/string/words.md).

# \_.words（拆分字符串为数组）

**语法：**

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

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L15212)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.words)

**描述：**

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

**开始版本：**&#x33;.0.0

**参数：**

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

**返回值：**

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

**例子：**

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

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