delete_index
less than a minute
Overview
The delete_index editor function removes one or more elements from an array by index. It supports removing a single element at a specific index or a range of elements between a start and end index.
Syntax
delete_index(target, index)
delete_index(target, startIndex, endIndex)
- target: the array field to modify
- index: the zero-based index of the element to remove (single element mode)
- startIndex: the zero-based start index of the range to remove (inclusive)
- endIndex: the zero-based end index of the range to remove (exclusive)
Examples
Remove a single element
Input
{
"_type": "log",
"body": {
"tags": ["alpha", "beta", "gamma", "delta", "epsilon"]
},
"resource": {...},
"attributes": {}
}
Statement
delete_index(body["tags"], 2)
Output
{
"_type": "log",
"body": {
"tags": ["alpha", "beta", "delta", "epsilon"]
},
"resource": {...},
"attributes": {}
}
The element at index 2 ("gamma") was removed. The remaining elements shifted left to fill the gap.
Remove a range of elements
Input
{
"_type": "log",
"body": {
"numbers": [10, 20, 30, 40, 50]
},
"resource": {...},
"attributes": {}
}
Statement
delete_index(body["numbers"], 1, 3)
Output
{
"_type": "log",
"body": {
"numbers": [10, 40, 50]
},
"resource": {...},
"attributes": {}
}
Elements at indices 1 and 2 (20 and 30) were removed. The range is half-open: start index 1 is inclusive, end index 3 is exclusive.