Find
  • 27 May 2022
  • 1 Minute to read
  • Dark
    Light
  • PDF

Find

  • Dark
    Light
  • PDF

Finds the first item from the given list 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 list. The formula must result in a true/false value. If true, then item will be included to the result, otherwise it will be excluded.

Function signature

FIND(list: Array, selectionformula: Function) => Object|Undefined
Parameter Description
List List of items to search
Selection formula Formula used to determine if an item is the one to find from the list

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"}

Was this article helpful?

What's Next