THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript String repeat() method

JavaScript String Reference JavaScript String Reference

Example

Make new string by copying a string twice:

var str = "Hello world!";
str.repeat(2);

The result would be:

Hello world!Hello world!
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 No 24.0 9 28.0

Note: The repeat() method is not supported in Internet Explorer 11 and earlier versions.


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 JavaScript String Reference