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

Select

  • Dark
    Light
  • PDF

Selects items from a list that match the given criteria. Returns a list containing only the matching items, in their corresponding order.

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

SELECT(list: Array, filteringformula: Function) => Array
Parameter Description
List List of items to filter
Filtering formula Formula to be evaluated for each item, deciding whether to include or not to the result 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
SELECT(animals, item.weight > 100) [{"name":"dog","weight":123},{"name":"pig","weight":230}]
SELECT(animals, IS_ODD(index)) [{"name":"cat","weight":48},{"name":"pig","weight":230}]
SELECT<product>(products, product.category == "Utility") [{"name":"Duct tape","category":"Utility"},{"name":"Glue","category":"Utility"}]
SELECT<product, position>(products, position < 2 && product.category == "Utility") [{"name":"Duct tape","category":"Utility"}]

Was this article helpful?

What's Next