JavaScript (ES2026) reference · String Methods

JavaScript String repeat() Method

Return a new string made of this string repeated a given number of times, for example to build separators or padding.

JavaScript (ES2026) Since ES2015

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

string.repeat(count)

Parameters

ParameterDescription
count How many copies, from 0.

Return value

A new string.

Examples

Repeat textTry it yourself
console.log("ab".repeat(3), JSON.stringify("x".repeat(0)));

Output

ababab ""
Underline a titleTry it yourself
const title = "Report";
console.log(title);
console.log("=".repeat(title.length));

Output

Report
======

Version history

VersionChange
JavaScript ES2015Added

In other languages

Was this page helpful?