repeat

Learn how to use the repeat function in Notion formulas.

The repeat() function will repeat a string the specified number of times.

repeat(string, number)

string.repeat(number)
Code language: JavaScript (javascript)

If you specify a non-string data type as the first argument, it will be converted to a string before being repeated.

123.repeat(3) /* Output: "123123123" */

false.repeat(3) /* Output: "falsefalsefalse" */Code language: CSS (css)
"This is " + "very ".repeat(3).split(" ").join(", ") + " good."
Code language: JavaScript (javascript)

The repeat() function has a clever trick up its sleeve – you can use it to essentially create for loops within Notion formulas!

Notion’s formula language doesn’t include actual looping functions, unlike most programming languages. For example, JavaScript makes it easy:

const arr = []

for (let i = 0; i < 5; i++) {
  const number = i * 2;
  arr.push(number);
}
Code language: JavaScript (javascript)

However, you can combine repeat() with split to replicate this functionality:

"."
  .repeat(10)
  .split(".")
  .map(
    index * 2
  )
Code language: JavaScript (javascript)

This is about the simplest demonstration of this trick.

A . character is repeated 10 times to create the string “……….”, which is then split on the same character to create a List of length 10. Finally, we map through the list, multiplying each item’s index by 2.

You can see a more in-depth example at my For Loops with Custom Number of Iterations example formula page.

About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.

🤔 Have an UB Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas

🤔 Have a Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas