Nodes/ComfyUI Impact Pack/Select Nth Item (Any list)
ComfyUI Node Runs on cloud

Select Nth Item (Any list)

Pull one item out of a list

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,242
Select Nth Item (Any list)
  • any_list
  • *
index0

Lots of ComfyUI nodes emit a list - a batch of images split into individual items, a stack of masks, a set of latents. Sometimes you only want one of them. Select Nth Item (Any list) grabs the item at the index you name and passes it on. That's the entire job, and it's the kind of small utility you don't think about until a workflow hands you five images and you need the third.

The genuinely nice touch is the out-of-range behavior: if you ask for an index past the end of the list, it returns the last item instead of erroring. That means you can point it at "item 5" of a list that sometimes has three items and sometimes six, and it degrades gracefully instead of crashing your run.

How it works

The node takes a wildcard-typed list and an integer index, and returns the single element at that position. Because the input is wildcard-typed, it works on a list of anything - images, masks, latents, strings. Index out of bounds clamps to the last element rather than throwing. Simple, forgiving, done.

The inputs and outputs that matter

  • any_list - the list to pick from. Wildcard-typed, so any list works. Note it needs to be an actual list output (an is_list connection), not a batch tensor - those are different things in ComfyUI, and it's the source of most confusion here.
  • index (default 0) - which item to grab. Zero-indexed: 0 is the first item, 1 the second. Ask for an index beyond the list and you get the last item.

The single output is a wildcard (*) - the selected item, same type as whatever the list held.

How to install it

Ships with the Impact Pack. ComfyUI Manager: search ComfyUI Impact Pack, Install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
pip install -r requirements.txt

then restart. No models needed.

Common issues & troubleshooting

You always get the last item, no matter the index. Your index is larger than the list length, so the clamp kicks in and hands you the final element. Double-check how many items the list actually has - and remember indexing starts at 0, so a 3-item list has valid indices 0, 1, 2.

It's not treating your input as a list. ComfyUI distinguishes a list (separate items) from a batch (one stacked tensor). If your upstream node outputs a batch, convert it first - for images that's an "Image Batch to Image List" node (Impact Pack has one). Feed a real list in and the selection works.

Off-by-one versus other Impact Pack nodes. Heads up: this node is 0-indexed, but the switch nodes in the same pack (Switch, Inversed Switch) are 1-indexed. It's an easy trap when you're wiring both in one graph - the first item here is index 0, not 1.

CategoryImpactPack/Util

Inputs (2)

NameTypeDefaultDescription
any_list*
indexINT0-9223372036854776000–9223372036854776000The index of the item you want to select from the list. Use negative values to select from the end (e.g., -1 for last item, -2 for second to last).

Outputs (1)

NameTypeDescription
**