A list data type stores a collection of items which can be accessed and manipulated with other functions. Lists are typically called arrays in most programming languages, and they greatly increase the functionality of Notion formulas.
Lists are surrounded by square brackets [
]
and can contain strings, numbers, booleans, dates, and other lists.
["Apples", "Oranges", "Pears"]
[1, 2, 3]
[true, false, false]
[now(), prop("Date")]
[["Luffy", "Zoro"], ["Nami", "Chopper"]]
Code language: JavaScript (javascript)
While lists can be made up of different data types, all non-string items will be converted to strings for the live preview. Their original data types will be retained when accessing each item directly.
["Apples", 1, true, now(), ["Luffy", "Zorro"]]
/* Live Preview: "Apples, 1, true, @September 7, 2023 9:00 AM, Luffy, Zorro" */
["Apples", 1, true, now(), ["Luffy", "Zorro"]].at(0)
/* Output: "Apples" */
["Apples", 1, true, now(), ["Luffy", "Zorro"]].at(1)
/* Output: 1 */
["Apples", 1, true, now(), ["Luffy", "Zorro"]].at(2)
/* Output: true */
["Apples", 1, true, now(), ["Luffy", "Zorro"]].at(3)
/* Output: @September 7, 2023 9:00 AM */
["Apples", 1, true, now(), ["Luffy", "Zorro"]].at(4)
/* Output: ["Luffy", "Zorro"] */
Code language: JavaScript (javascript)
List Functions
Many formula functions are designed to work with lists. Here’s a full list:
- at
- first
- last
- slice
- concat
- sort
- reverse
- join
- split
- unique
- includes
- find
- findIndex
- filter
- some
- every
- map
- flat
Built-in Variables for Lists
- current
- index
When using a function like map on a list, a list item’s value and its place in the original list can be accessed with current
and index
respectively.
["Luffy", "Zoro", "Nami", "Chopper"].map(
current
+ " is number "
+ (index + 1)
+ " in the list"
)
/* Output:
Luffy is number 1 in the list,
Zoro is number 2 in the list,
Nami is number 3 in the list,
Chopper is number 4 in the list */
Code language: JavaScript (javascript)
Lists use zero-based indexing, which means the first element in a list has an index (i.e. position) of 0
.