_.findLastIndex
_.findLastIndex finds the match nearest the end
- py_list
- predicate
- INT
_.findIndex scans left to right. _.findLastIndex does the same search from the right, so it returns the index of the match closest to the end of the array. Everything else is identical: run a truth test per element, return the first index that passes, hand back -1 when nothing does.
It's one of the auto-generated _.* wrappers in sfinktah/comfy-ovum, built on underscore3 (a Python port of Underscore.js). The whole family shares one design, and this one is the "array method" variant, so the primary input is named py_list.
When you'd use it
Any time "the last one that matches" is more meaningful than "the first." Think of a list of generations or intermediate results where you want the most recent item that satisfies a condition - the last tag with a confidence above a threshold, the last frame that had a face detected. Because the output is a plain INT index, it drops straight into indexing, slicing, or loop-cursor nodes. -1 is the "not found" signal you branch on.
The inputs that matter
- py_list - the array to search (loose
*; also accepts a_.CHAIN). - predicate - the truth test,
ANYinput. - predicate_json - the practical one. When
predicateisn't connected, this multiline string is parsed as JSON or used as a selector. A key name in quotes -"ok"- finds the last item where that key is truthy; an object like{"ok": true}does shorthand matching; a number compares values directly.
Output is typed INT, which is rare and useful in this family - most of its siblings return a loose *.
Install
Same as the rest of the pack. ComfyUI Manager, search "comfy-ovum", or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart, look under ovum/underscore. No models, no downloads.
Honest warnings
The author's README disclaimer covers this whole family: work in progress, not for production. Also note the subtle behavioral point - reverse iteration means if your predicate matches every element, you get the last index (len-1), not 0; people expecting "first match" semantics get surprised here. And remember predicate_json needs strict JSON: quote your key names.
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 | — |