List Index (NH)
Grab the Nth item out of a list, cleanly
- items
- item
- is_first
- is_last
- count
You've got an NH_LIST and you want one item out of it - the third prompt, the fifth filename, the last entry. List Index (NH) (class NH_ListIndex) is the pick-it-out node: give it the list and an index, and it returns that item as a string, plus is_first, is_last, and the total count for free. Simple, but the little flags are what make it genuinely useful in logic.
How it works
It takes items (an NH_LIST from List Create (NH) or List Filter (NH)) and an index integer. Indexing is 0-based - index 0 is the first item - and there's a wrap toggle:
- wrap = true (default): the index is taken modulo the list length, so index -1 is the last item and index
countwraps back to the start. No out-of-bounds errors, ever. - wrap = false: negative indices use Python-style counting from the end (
-1= last), and positive indices clamp to the last item instead of erroring.
Outputs are item (the selected string), is_first, is_last (both BOOLEANs - wire these into a Logic Gate (NH) or switch), and count (list length, handy when you're indexing based on the size).
Where you'd actually use it
This is the selection workhorse of the NH list trio. Typical graph: List Create (NH) builds your list, List Index (NH) picks the item based on a number you can drive from a slider or a seed, and the resulting string feeds a prompt or filename node. The is_last flag is the killer feature for loop-ish workflows: it lets you branch once you've hit the end of the list instead of guessing lengths.
Installing
From ComfyUI Manager, search NH-Nodes, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt
Restart ComfyUI and refresh the browser page. Pure Python, no extra deps.
Gotchas
Two things. First, an empty list returns an empty string with both is_first and is_last true - which reads as "the only item" if you're not careful, so guard against it if your list can be empty. Second, remember the pack's NH_LIST type is not ComfyUI's native list, so this node only connects to NH list sockets - feed it a plain string and it won't type-check. Minor quirk: index min is -100, so wrap mode with very negative numbers still wraps correctly via modulo, but there's no real reason to go there.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| items | NH_LIST | — | |
| index | INT | 0-100–1000 | — |
| wrapopt | BOOLEAN | true | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| item | STRING | — |
| is_first | BOOLEAN | — |
| is_last | BOOLEAN | — |
| count | INT | — |