JavaScript String repeat()

Basics

The String repeat() method is a very fun one. You can take any string and repeat over it so that it displays multiple times.

"hello ".repeat(5);
// output: hello hello hello hello hello

It can also work with emojis!

"🔥✨🚀".repeat(10);

// output: 🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀🔥✨🚀

This can be useful as filler text or for annoying your friends.

Syntax

myString.repeat(numberOfTimesToRepeat);

1 parameter

count (integer)

The number of times you want to repeat over the string.

Returns a new string

Repeat() does not affect the original string. It creates a new one and returns that.