Javascript - String repeat() Method

The repeat() method returns a new string with a specified number of copies.

Description

The repeat() method returns a new string with a specified number of copies.

Syntax

string.repeat(count)

Parameter Values

Parameter Require Description
count Required.The number of times the original string should be repeated in the new string

Return

A String, a new string containing copies of the original string

Example

Make a new string by copying a string twice:

Demo

//Make a new string by copying a string twice:
var str = "Hello world!";
console.log(str.repeat(2));

Result