JS: String.prototype.repeat() function

The String.prototype.repeat() function repeats a given string for a number of time. The count is given as parameter to the function.

Advertisements
Advertisements

The general syntax is given below.

string.repeat(count);

Usage

<!DOCTYPE html>
<html>
<head>
   <title>String.prototype.repeat()</title>
   <meta charset="utf-8">
</head>
<body>
<main>
<h1 id="out">Output here</h1>
<p>Program to repeat a string using String.prototype.repeat() JavaScript function.</p>
</main>
<script>
var str = "Elephant";

document.getElementById("out").innerHTML = str.repeat(3);

</script>

</body>
</html>

Output: repeat() function

Output - JavaScript repeat() function
Output – JavaScript repeat() function

Advertisements

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.