A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat below:

String.prototype.repeat() - JavaScript | MDN

String.prototype.repeat()

Baseline Widely available

The repeat() method of String values constructs and returns a new string which contains the specified number of copies of this string, concatenated together.

Try it
const mood = "Happy! ";

console.log(`I feel ${mood.repeat(3)}`);
// Expected output: "I feel Happy! Happy! Happy! "
Syntax Parameters
count

An integer between 0 and Infinity, indicating the number of times to repeat the string.

Return value

A new string containing the specified number of copies of the given string.

Exceptions
RangeError

Thrown if count is negative or if count overflows maximum string length.

Examples Using repeat()
"abc".repeat(-1); // RangeError
"abc".repeat(0); // ''
"abc".repeat(1); // 'abc'
"abc".repeat(2); // 'abcabc'
"abc".repeat(3.5); // 'abcabcabc' (count will be converted to integer)
"abc".repeat(1 / 0); // RangeError

({ toString: () => "abc", repeat: String.prototype.repeat }).repeat(2);
// 'abcabc' (repeat() is a generic method)
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4