JavaScript repeat() | Repeat String n Times

The JavaScript repeat() method is used when we need to repeat a string for n number of times. For example:

HTML with JavaScript Code
<!DOCTYPE html>

   <p id="xyz"></p>

      let myString = "";
      let res = myString.repeat(3);
      document.getElementById("xyz").innerHTML = res;

JavaScript repeat() Syntax

The syntax of repeat() method in JavaScript is:


The n argument is required, refers to a number that is used to create number of copies of specified string..

JavaScript Online Test

« Previous Tutorial Next Tutorial »

Follow/Like Us on Facebook

Subscribe Us on YouTube