Lodash - padEnd 方法

语法

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

如果字符串短于长度,则在右侧填充字符串。如果填充字符超过长度,则将被截断。

参数

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

  • [length=0] (number) − 填充长度。

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

输出

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

示例

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

console.log(result);

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

foo_____

lodash_string.html