type_AnyIndex
Grab element N from a list or a batch — negatives count from the end
- any
- out
"You can't just index a list in ComfyUI" is a sentence people say until they've found a node like this. type_AnyIndex takes an any-typed collection and returns a single element by position - the node's own tooltip states the one rule that matters: indexing starts at 0, and negative numbers count from the end (−1 is the last element). That's the entire contract, and it makes the node trivial to use and easy to trust.
It's from the data drawer of ComfyUI-Apt_Preset, and it's one of those small nodes that feels obvious once you've needed it.
How it works
Feed any a list, a tuple, or a batch tensor. The node figures out what it's dealing with:
- A list-typed output (something whose OUTPUT_IS_LIST is true) - indexes into the list.
- A batch tensor - indexes the batch axis, returning a single-element slice (shape preserved).
- A plain container - indexes it directly.
Index handling is where it's nicer than raw Python: negatives are resolved against the actual length (-1 → last element), and out-of-range values get clamped to the nearest valid index instead of raising. There's a hidden bit of cleverness too - the node inspects the upstream node's declared output type, so it knows whether it's handling a list or a batch without you telling it. Feed it an image batch and index 2 gives you frame 2; feed it a list of prompts and -1 gives you the last prompt.
Inputs and outputs
- any - the collection (any-type).
- index - INT, 0-based, negatives from the end. Default 0.
- Output: out - the selected element, any-type.
Practical uses: pull one prompt out of a wildcard batch for a specific branch, grab the first frame of a video batch to preview, select a single conditioning from a list. Pair it with an unpacker or a loop-like structure and it covers the "I just want element k" cases that ComfyUI's fixed sockets make awkward.
Installing it
Part of ComfyUI-Apt_Preset. ComfyUI Manager → search ComfyUI-Apt_Preset, or:
cd ComfyUI/custom_nodes
git clone https://github.com/cardenluo/ComfyUI-Apt_Preset
Restart; install.bat on Windows for the pack's requirements. Nothing extra for this node.
Common issues
The main confusion is 0-based vs 1-based indexing - the node is 0-based (tooltip says so explicitly), so "first element" is 0, and people who think in spreadsheet terms grab the wrong item once. Clamping hides the other failure mode: if you index past the end, you silently get the last element rather than an error, which can be a confusing result to debug downstream. If you index empty collections you get the empty result back rather than a crash - again, forgiving. Verify your index against the actual length when the output looks wrong, and it'll be the least dramatic node in your graph.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| any | * | — | |
| index | INT | 0-999990–1000000 | 从0开始,0对应第一个元素;负数表示倒数,-1为最后一个元素 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| out | * | — |