SELECT

Select specific items from array

Description

Selects items from an array that match the given criteria. Returns an array 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 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

SELECT(array: Array, filteringformula: Function) => Array

Parameter

Description

Array

Array of items to filter

Filtering formula

Formula to be evaluated for each item, deciding whether to include or not to the result 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

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