List.RemoveRange
ListRemoves a specified number of items from a list starting at a given index position.
Syntax
List.RemoveRange(list as list, index as number, optional count as nullable number) as listParameters
| Name | Type | Required | Description |
|---|---|---|---|
list | list | Yes | The source list. |
index | number | Yes | The zero-based index at which to start removing items. |
count | nullable number | No | The number of items to remove. Defaults to 1 if not specified. |
Return Value
list — A new list with the specified range of items removed.
Remarks
List.RemoveRange removes a contiguous block of items from a list by position, returning a new list without the removed items. The index is zero-based and specifies where removal starts; count specifies how many items to remove. If count is omitted, a single item is removed.
An index of 0 starts removal from the first item. If count extends beyond the end of the list, all items from index onward are removed — no error is raised for over-counting. The original list is not modified.
This is a position-based removal function. For value-based removal (remove items matching a certain value), use List.RemoveMatchingItems or List.Select. For removing from the front, List.RemoveFirstN is more readable. For replacing a range rather than just removing it, use List.ReplaceRange.
Examples
Example 1: Remove 2 items starting at index 1
List.RemoveRange({1, 2, 3, 4, 5}, 1, 2)Result | |
|---|---|
| 1 | {1, 4, 5} |
Example 2: Remove a single item (default count)
List.RemoveRange({"A", "B", "C", "D"}, 2)Result | |
|---|---|
| 1 | {A, B, D} |
Example 3: Remove from the middle of a list
let
Months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun"},
WithoutQ2 = List.RemoveRange(Months, 3, 3)
in
WithoutQ2The final output — the list with Q2 months removed, containing only Jan, Feb, and Mar.
Result | |
|---|---|
| 1 | {Jan, Feb, Mar} |