Nodes/comfy-ovum/_.contains
ComfyUI Node

_.contains

Ask a list “does this value live in here?”

By sfinktah·Created about a year ago·Updated 10 months ago· 7
_.contains
  • list_or_dict
  • value
  • BOOLEAN
fromIndex0

_.contains is a membership test for the graph: it answers yes/no to "is this value in this collection?" and hands you a BOOLEAN you can feed into a conditional or switch. It's the kind of node you reach for when you're building guard logic - "only run this branch if the tag list actually contains 'sunset'", "skip this step unless the seed is in the allowed set", "did this prompt list include a banned term?" Everything downstream of Comfy's boolean/conditional nodes can now be driven by actual list inspection instead of hard-coded toggles.

The author's description is the classic Underscore behavior: "Returns true if the value is present in the list. Uses indexOf internally, if list is an Array. Use fromIndex to start your search at a given index."

How it works

Generated wrapper around underscore3, the bundled Python port of Underscore.js. Under the hood it's essentially an indexOf check: if the value is found at index 0 or later, it's true; otherwise false. Because it's the Python port, equality is Python equality - so 1 and 1.0 count as the same thing, and string matching is exact and case-sensitive. No fuzzy matching here; if you want case-insensitive or partial matching, normalize the strings upstream.

Inputs and output

Three inputs:

  • list_or_dict (any type) - the collection to search. Works on lists and dicts (and accepts a _.CHAIN to continue a chain).
  • value (any type) - the thing you're looking for. JSON is allowed for arrays/objects if you're searching for a structured value.
  • fromIndex (INT, default 0) - where to start the search. Handy if the same value legitimately appears early but you only care about a later occurrence.

Output: a single BOOLEAN. Wire it into an IfElseOvum or any boolean-expecting input, or feed the family's predicate sockets with it. If you chain it (pass in a _.CHAIN), it continues the chain and the boolean result comes out of the method call - which is how the library is meant to compose.

Installing it

Part of sfinktah/comfy-ovum ("comfy-ovum"):

  • ComfyUI Manager: search "comfy-ovum", install, restart.
  • Manual: cd ComfyUI/custom_nodes && git clone https://github.com/sfinktah/comfy-ovum, restart.

No model downloads; the dependencies are the pack's usual light set and underscore3 is bundled.

Small print

Two things to remember. First, fromIndex defaults to 0, and a negative index would count from the end the way Python slices do - so if you're hunting from the tail, you can do that too. Second, the whole underscore family is flagged as work-in-progress by the author, so for a critical branch in a "production" workflow, a hand-rolled compare node might be the safer bet. For quick and dirty "is it in the list" logic, _.contains is exactly what it says on the tin.

Categoryovum/underscore

Inputs (3)

NameTypeDefaultDescription
list_or_dictopt*Primary input object (expected collection). You can still pass any JSON-serializable value. Also accepts _.CHAIN to continue chaining.
valueopt*value: JSON allowed for arrays/objects where applicable.
fromIndexoptINT0fromIndex (int)

Outputs (1)

NameTypeDescription
BOOLEANBOOLEAN