THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript String repeat() method

❮ JavaScript String Reference

Example

Make a new string by copying a string twice:

var str = "Hello world!";
str.repeat(2);
Try it Yourself »

Definition and Usage

The repeat() method returns a new string with a specified number of copies of the string it was called on.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method
repeat() 41.0 12.0 24.0 9 28.0

Syntax

string.repeat(count)

Parameter Values

Parameter Description
count Required. The number of times the original string value should be repeated in the new string

Technical Details

Return Value: A String, a new string containing copies of the original string
JavaScript Version: ECMAScript 6

❮ JavaScript String Reference