How to repeat a string in JavaScript?

To repeat a string in JavaScript, do this: string.repeat(times).

Here's how you do it:

const string = 'Hello World!';

const repeated = string.repeat(3);

console.log(repeated); // Hello World!Hello World!Hello World!