_.only
Values for Lists, Keys for Dicts
- obj
- values
- *
_.only is the "keep just these" filter. Give it a list and a set of values, and it returns only the elements that match. Give it a dict and a set of keys, and it returns only those entries. It's the inverse of _.without, and a list-friendly cousin of _.pick.
What it does
The behavior switches on what you feed it:
- Lists -
[1, 2, 3, 4, 5]with values2, 4returns[2, 4]. It keeps elements whose value is in your keep-list. - Dicts -
{"a": 1, "b": 2, "c": 3}with keysa, creturns{"a": 1, "c": 3}. It keeps entries whose key is in your keep-list.
Same node, two personalities, decided by the input type. That dual behavior is the thing to remember - on a dict it filters keys, on a list it filters values.
The inputs:
obj- the list or dict (or a_.CHAIN)values- the keep-list. For multiple values, pass a JSON array like[1,2,3]; the tooltip is explicit about this
Output is a single ANY slot that carries whatever you put in, filtered.
The JSON-array habit
values is an ANY socket, and the one mistake people make is typing 1, 2, 3 into it and getting nothing sensible back. This family parses JSON on those inputs, so you want [1, 2, 3] for a keep-list of several values. A single value works bare, but get into the habit of JSON arrays early - it transfers to _.pick, _.omit and the predicate nodes in the same pack.
Where it fits
The realistic use is data hygiene: you've got a list of candidate values and you only care about a few of them, or you've got a dict and you're keeping a short allowlist of keys. It's a niche that overlaps with _.pick, but _.only also handles lists, which pick doesn't. For "this dict but only these three fields," _.pick is arguably clearer; for "this list but only these values," _.only is the one.
Installing
Ships in comfy-ovum. ComfyUI Manager → search comfy-ovum → Install, or:
cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum
Restart ComfyUI. No models, no extra pip packages for the underscore nodes - the underscore.js port is bundled in the repo.
The bottom line
A dual-mode keep-filter: values for lists, keys for dicts. Feed it JSON arrays for multiple keep-items and it'll do exactly what the name promises.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| objopt | * | Primary input object. Also accepts _.CHAIN to continue chaining. | |
| valuesopt | * | values: JSON allowed for arrays/objects where applicable. For multiple values, provide a JSON array (e.g., [1,2,3]). |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |