> 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/trim.md).

# \_.trim（移除两侧空格或指定字符）

**语法：**

```javascript
_.trim([string=''], [chars=whitespace])
```

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

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

**描述：**

从`string`字符串中移除前面和后面的 空格 或 指定的字符。

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

**参数：**

* `[string=''] (string)`: 要处理的字符串。
* `[chars=whitespace] (string)`: 要移除的字符。&#x20;

**返回值：**

* `(string)`: 返回处理后的字符串。

**例子：**

```javascript
_.trim('  abc  ');
// => 'abc'

_.trim('-_-abc-_-', '_-');
// => 'abc'

_.map(['  foo  ', '  bar  '], _.trim);
// => ['foo', 'bar']
```
