Lodash - trim 方法



語法

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

刪除字串中前導和尾隨空白或指定字元。

引數

  • [string=''] (string) − 要修剪的字串。

  • [chars=whitespace] (string) − 要修剪的字元。

輸出

  • (string) − 返回修剪後的字串。

示例

var _ = require('lodash');
var result = _.trim('__abc__', '_');

console.log(result);

將上述程式儲存在 tester.js 中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

abc
lodash_string.htm
廣告
© . All rights reserved.