The findIndex()
function will return the index number of the first item in a list that matches the condition. If you want to return the item itself, use find.
findIndex(list, condition)
list.findIndex(condition)
Code language: JavaScript (javascript)
Note that lists use zero-based indexing, so 0
will be returned for the first value.
Example Formulas
This formula finds the index of the first item in the list that can be parsed to a date:
[1, "Monkey D. Luffy", true, "2025-01-01", 37, "1999-12-23"].findIndex(
current.parseDate()
)
/* Output: 3 */
Code language: JavaScript (javascript)
This variation finds the index of the first item that can be parsed to a date and that is before Jan 1, 2000:
[1, "Monkey D. Luffy", true, "2025-01-01", 37, "1999-12-23"].findIndex(
current.parseDate() < "2000-01-01".parseDate()
)
/* Output: 5 */
Code language: JavaScript (javascript)