_.findIndex
When you want the position, not the item
- py_list
- predicate
- INT
_.find answers "which one?" _.findIndex answers "where?" It scans an array left to right, runs a truth test against each element, and returns the index of the first match - or -1 if nothing matches. Same search, different output, and for graph plumbing the index is often the more useful thing.
It's part of the _.* family in sfinktah/comfy-ovum - auto-generated wrappers around underscore3, a Python port of Underscore.js. Every node in the family shares the same design, and this one is the "collection method" variant: it expects an array.
Why the index is useful
Because an index plugs straight into every other list-ish node in ComfyUI. You can feed the returned INT into a list-indexing or slicing node to grab the element, or use it as a cursor to drive a loop. One genuinely handy pattern: keep a list of model names and find where "sdxl" sits, then use that position to select something else in a parallel list that's aligned by index. -1 is your "not found" signal - feed it to an IfElse-style node to branch.
The inputs that matter
- py_list - the array to search (a loose
*input, so it also accepts a_.CHAIN). - predicate - the truth test. An
ANYinput for a wired-in function. - predicate_json - the practical one. A multiline string parsed as JSON when
predicateisn't connected. Type a key name in quotes, e.g."active", to find the first item where that key is truthy; or{"active": true}for object-shorthand matching; or a number to compare values directly.
The output is typed INT, which is a nice change of pace in this family - most of these nodes return a loose * and leave you guessing. findIndex gives you something you can wire straight into a math or indexing node.
Install
Same as every node in this pack - ComfyUI Manager, search "comfy-ovum", or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart, then find it under ovum/underscore. No models, no downloads.
Honest warnings
The family-wide caveat applies: the author calls these a work in progress not meant for production. Also remember it returns the first match from the left. If you need the match nearest the end, that's _.findLastIndex instead. And the predicate_json parsing is strict JSON - a bare word like active won't parse; wrap it in quotes.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| py_listopt | * | Primary input object (expected array). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining. | |
| predicateopt | * | predicate: ANY input to override widget. Accepts function, key string, or object shorthand. | |
| predicate_jsonopt | STRING | predicate_json: JSON or key selector. Used when 'predicate' input is not connected. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |