repeat()
repeat(
str,count):string
Repeats a string a specified number of times.
DEPRECATED
Use string.repeat() directly instead.
Parametersβ
str: string | null | undefinedβ
The string to repeat.
count: number | null | undefinedβ
The number of times to repeat the string.
Returns: stringβ
The repeated string.
See Alsoβ
Sinceβ
2.0.0
Also known asβ
repeat (Lodash, es-toolkit) Β· β (Remeda, Radashi, Ramda, Effect, Modern Dash, Antfu)
Exampleβ
// β Deprecated approach
repeat('hello', 3); // => 'hellohellohello'
repeat('-', 10); // => '----------'
// β
Recommended approach
'hello'.repeat(3); // => 'hellohellohello'
'-'.repeat(10); // => '----------'
How it works?β
Repeats a string n times.
Deprecated: Use string.repeat() directly (ES2015).
Native Equivalentβ
// β repeat('ab', 3)
// β
'ab'.repeat(3)
Use Casesβ
Repeat string πβ
Repeat string n times.
"ab".repeat(3); // => "ababab"
"-".repeat(10); // => "----------"
Create separatorβ
Build visual separators.
const divider = "=".repeat(40);
console.log(divider);
Indent codeβ
Create indentation.
const indent = " ".repeat(level);
const line = indent + content;