Powered By GitBook
SET_ITEM_AT
Updates an index in list

Description

Sets a value in the given list at the given index to a new value. Returns a list where the item at the index has been replaced with a new value. Alternatively, if the array is shorter than the given index, then its length is increased, filling the new indexes with undefined values.
If the index is negative, then the position is calculated from the end of the array, so that -1 means the last index, etc.
The 3rd parameter defines either the value to be set at the index, or a formula that can use the existing item at the index and result in a new value. For example, the formula can use SET\_KEY function to update a property of an existing item to a new value.

Function signature

1
SET_ITEM_AT(list: Array, index: Number, newitemformula: Function) => Array
Copied!
Parameter
Description
List
List of items
Index
Index of the list, starting from 0, defining the position at which to set the new value.
New item formula
A new item to be set at the index replacing any previous item, or a formula to be evaluated using the existing item for the replacement value

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
products = [
16
{
17
"name": "Duct tape",
18
"price": 2.9
19
},
20
{
21
"name": "Swiss army knife",
22
"price": 23
23
},
24
{
25
"name": "Glue",
26
"price": 1.5
27
}
28
]
Copied!
Formula
Return value
SET_ITEM_AT(animals, 1, { name: "horse", weight: 600 })
[{"name":"dog","weight":123},{"name":"horse","weight":600},{"name":"rat","weight":10}]
SET_ITEM_AT(animals, 1, SET_KEY(item, "weight", 23))
[{"name":"dog","weight":123},{"name":"cat","weight":23},{"name":"rat","weight":10}]
SET_ITEM_AT(animals, -1, SET_KEY(item, "name", "horse"))
[{"name":"dog","weight":123},{"name":"cat","weight":48},{"name":"horse","weight":10}]
SET_ITEM_AT<product>(products, 0, SET_KEY(product, "price", product.price * 2))
[{"name":"Duct tape","price":5.8},{"name":"Swiss army knife","price":23},{"name":"Glue","price":1.5}]
SET_ITEM_AT<letter, position>(["a", "b", "c", "d", "e"], -2, UPPERCASE(letter) + "!")
["a","b","c","D!","e"]
SET_ITEM_AT(["a", "b"], 5, "c")
["a","b",null,null,null,"c"]
Last modified 10mo ago
Export as PDF
Copy link