ES6 - String.prototype.repeat()



This function constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together.

Syntax

The below mentioned syntax is for the function String.prototype.repeat(), where, count indicates the number of times to repeat the string in the newly-created string that is to be returned.

str.repeat(count)

Example

<script>
   let name="Kiran-"
   console.log(name.repeat(3));
</script>

The output of the above code will be as shown below −

Kiran-Kiran-Kiran-
Advertisements