The includes()
function returns true if the list in the first argument contains the value specified in the second argument.
includes(list, value)
list.includes(value)
Code language: JavaScript (javascript)
Example Formulas
["Luffy", "Sanji", "Nami"].includes("Sanji")
/* Output: true */
Code language: JavaScript (javascript)
You can also combine includes()
with functions like map in order to write a test for each element in a list. This test checks if the list contains any odd numbers:
if(
[2, 4, 6, 8, 9]
.map(
current % 2
)
.includes(1),
"List contains at least one odd number.",
"List contains all even numbers."
)
/* Output: "List contains at least one odd number." */
Code language: JavaScript (javascript)
In my Creator’s Companion template, I include a YouTube Chapters formula that generates a list of timestamps for the video, based off of B-roll items with the “Chapter” meta tag.
Since non-chapter B-roll items can also be related to a content project, I use includes()
inside of filter to get only the Chapter items:
prop("B-Roll")
.filter(
current.prop("Meta").includes("Chapter")
)
Code language: JavaScript (javascript)