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;