ES6 - New String Method repeat()



This function repeats the specified string for a specified number of times.

Syntax

str.repeat(count)

Parameters

  • Count − number of times the string should be repeated.

Return Value

Returns a new string.

Example

var myBook = new String("Perl"); 
console.log(myBook.repeat(2)); 

Output

PerlPerl 
Advertisements