Lodash - padEnd 方法



語法

_.padEnd([string=''], [length=0], [chars=' '])

如果字串比給定長度短,則在字串右側填充字元。如果填充字元超過給定長度,則對其進行截斷。

引數

  • [string=''] (字串) − 要填充的字串。

  • [length=0] (數字) − 填充長度。

  • [chars=' '] (字串) − 用作填充的字串。

輸出

  • (字串) − 返回填充後的字串。

示例

var _ = require('lodash');
var result = _.padEnd('foo', 8, '_');

console.log(result);

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

命令

\>node tester.js

輸出

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