flat

Learn how to use the flat function in Notion formulas.

The flat() function flattens multiple lists into a single list.

flat(list)

list.flat()
Code language: JavaScript (javascript)

Note that unlike the flat() function in JavaScript, you cannot specify the depth. Notion’s version will only flatten one “level” of lists.

When working with flat() and other list functions, I highly recommend clicking the Show Details icon. This will show the data type of your formula’s final return value, and it’ll also show the brackets that surround elements in any lists.

This is particularly useful when working with flat(), since you’ll likely be working with one or more nested lists.

The Show Details button clicked, showing the final return value of the formula with its data type.
flat([[1, 2], [3, 4]]) /* Output: [1, 2, 3, 4] */

[
  [ "Luffy", "Sanji"],
  [ "Nami", "Usopp"],
  [ "Chopper" ]
].flat()

/* Output: [Luffy, Sanji, Nami, Usopp, Chopper] */
Code language: JavaScript (javascript)

Here’s a case where you might use flat() – if you had a collection of multiple lists, you might want to find the element amongst all of them with the highest character count:

let(
  teams,
  [
    [ "Luffy", "Zoro", "Nami", "Usopp", "Sanji"],
    [ "Goku", "Vegeta", "Krillin"],
    [ "Iron Man", "Hulk", "Thor", "Captain America", "Black Widow", "Hawkeye"]
  ],
  teams.flat().sort(
    current.length()
  ).last()
)

/* Output: Captain America */
Code language: JavaScript (javascript)
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