Skip to content

padStart

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

如果 string 短于 length,则在左侧填充 string。如果填充字符超过 length,则会被截断。

¥Pads string on the left side if it's shorter than length. Padding characters are truncated if they exceed length.

新增于

¥Since

4.0.0

参数

¥Arguments

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

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

  2. [length=0] (数值):要检查的路径。

    ¥[length=0] (number): The padding length.

  3. [chars=' '] (字符串):用作填充的字符串。

    ¥[chars=' '] (string): The string used as padding.

返回

¥Returns

(字符串):返回填充后的字符串。

¥(string): Returns the padded string.

示例

¥Example

js
_.padStart('abc', 6);
// => '   abc'

_.padStart('abc', 6, '_-');
// => '_-_abc'

_.padStart('abc', 3);
// => 'abc'

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