String.repeat
String.repeat
Function
Repeat the current string the number of times.
Syntax
string.repeat(count)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| count | Int | No | 0 | Number of repetitions, negative numbers will be treated as 0. |
Return value
| Type | Description |
|---|---|
| String | Returns the new string after repetition. |
Example
text = 'ha' result = text.repeat(3) // Output: hahaha print result
Notes
- Returns an empty string when count is 0 or negative.