FIND

Finds an item from array

Description

Finds the first item from the given array that matches the given criteria. Returns that item, or null if not found.

The criteria is defined as a formula at the second parameter. The formula is evaluated with each item in the array. The formula must result in a boolean value. If true, then item will be included to the result, otherwise it will be excluded.

Function signature

FIND(array: Array, selectionformula: Function) => Object|Undefined

Parameter

Description

Array

Array of items to search

Selection formula

Formula used to determine if an item is the one to find from the array

Examples

animals = [
{
"name": "dog",
"weight": 123
},
{
"name": "cat",
"weight": 48
},
{
"name": "rat",
"weight": 10
},
{
"name": "pig",
"weight": 230
}
]
products = [
{
"name": "Duct tape",
"category": "Utility"
},
{
"name": "Swiss army knife",
"category": "Tools"
},
{
"name": "Glue",
"category": "Utility"
}
]

Formula

Return value

FIND(animals, item.name == "cat")

{"name":"cat","weight":48}

FIND(animals, item.name == "horse")

undefined

FIND(animals, index == 2)

{"name":"rat","weight":10}

FIND<product>(products, product.name == "Duct tape")

{"name":"Duct tape","category":"Utility"}

FIND<product, position>(products, position == 1)

{"name":"Swiss army knife","category":"Tools"}