Skip to content

trim

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

string 中删除前导和尾随空格或指定字符。

¥Removes leading and trailing whitespace or specified characters from string.

新增于

¥Since

3.0.0

参数

¥Arguments

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

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

  2. [chars=whitespace] (字符串):要修剪的字符。

    ¥[chars=whitespace] (string): The characters to trim.

返回

¥Returns

(字符串):返回修剪后的字符串。

¥(string): Returns the trimmed string.

示例

¥Example

js
_.trim('  abc  ');
// => 'abc'

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

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

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