Skip to content

repeat

js
_.repeat([string=''], [n=1])

重复给定的字符串 n 次。

¥Repeats the given string n times.

新增于

¥Since

3.0.0

参数

¥Arguments

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

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

  2. [n=1] (数值):重复字符串的次数。

    ¥[n=1] (number): The number of times to repeat the string.

返回

¥Returns

(字符串):返回重复的字符串。

¥(string): Returns the repeated string.

示例

¥Example

js
_.repeat('*', 3);
// => '***'

_.repeat('abc', 2);
// => 'abcabc'

_.repeat('abc', 0);
// => ''

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