Lodash - padStart 方法



語法

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

如果字串比長度短,則在左側填充字串。如果填充字元超出長度,則對其進行截斷。

引數

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

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

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

輸出

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

示例

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

console.log(result);

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

命令

\>node tester.js

輸出

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