Powered By GitBook
REMOVE_ITEM
Removes a matching item from list

Description

Removes the first item from a list that matches the given criteria. Returns a list all other items except the matching one, 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 until a matching item is found. The formula must result in a true/false value. If true, then item will be excluded from the result, otherwise it will be included. Note that only first matching item is removed; if multiple items matches the criteria, then only first one is removed. If no matching item is found, then the original list is returned unchanged.

Function signature

1
REMOVE_ITEM(list: Array, searchformula: Function) => Array
Copied!
Parameter
Description
List
List of items
Search formula
Formula to be evaluated for each item, deciding whether the item is the one to remove

Examples

1
animals = [
2
{
3
"name": "dog",
4
"weight": 123
5
},
6
{
7
"name": "cat",
8
"weight": 48
9
},
10
{
11
"name": "rat",
12
"weight": 10
13
},
14
{
15
"name": "pig",
16
"weight": 230
17
}
18
]
19
products = [
20
{
21
"name": "Duct tape",
22
"category": "Utility"
23
},
24
{
25
"name": "Swiss army knife",
26
"category": "Tools"
27
},
28
{
29
"name": "Glue",
30
"category": "Utility"
31
}
32
]
Copied!
Formula
Return value
REMOVE_ITEM(animals, item.name == "rat")
[{"name":"dog","weight":123},{"name":"cat","weight":48},{"name":"pig","weight":230}]
REMOVE_ITEM(animals, index == 1)
[{"name":"dog","weight":123},{"name":"rat","weight":10},{"name":"pig","weight":230}]
REMOVE_ITEM<product>(products, product.name == "Swiss army knife")
[{"name":"Duct tape","category":"Utility"},{"name":"Glue","category":"Utility"}]
REMOVE_ITEM<product, position>(products, position > 1 && product.category == "Utility")
[{"name":"Duct tape","category":"Utility"},{"name":"Swiss army knife","category":"Tools"}]
Last modified 10mo ago
Export as PDF
Copy link