Nodes/honda-nodes/πŸ“‹ Array Length
ComfyUI Node

πŸ“‹ Array Length

Counting lines, and the blank one you didn't know was there

By AvarayΒ·Created 14 days agoΒ·Updated 12 days agoΒ· 0
πŸ“‹ Array Length
    • Count
    β—„arrayβ€”β–Ί
    β—„count_emptyfalseβ–Ί

    A number you can act on

    Every ComfyUI workflow that touches lists eventually needs to know how long the list is. Not for display - for decisions. How many images are in this folder? Did the filter leave anything? Am I at the end of the batch? Array Length answers exactly that and emits a single INT.

    It's a one-job node and you should treat it that way. If you're pulling a count off πŸ“‹ Array Filter or πŸ“‹ Array Slice, you already have one on their Count output and you don't need this. Reach for Array Length when the list comes from a text node or πŸ“‚ Read File and nothing upstream is counting for you.

    How it works

    Split on newlines, count. The interesting part is the toggle: Count Empty is off by default, which means the count ignores lines that are blank after stripping whitespace. So a text block with a stray trailing newline, or a triple-spaced list pasted from a document, gives you the number you'd expect to see with your eyes rather than the number Python would give you.

    Turn Count Empty on and you're counting raw lines, which is what you want if blank lines are meaningful - a paragraph-separated prompt file where the gaps delimit sections, for instance. For almost everything else, leave it off; the default is the useful one and it's the reason this node's Count and πŸ“‹ Array Get Item's indexing don't always agree.

    That mismatch deserves a sentence of its own, because it's the classic trip-up: Array Length skips empties, Array Get Item doesn't. If your text block ends with a newline, Length might say 5 while item index 5 still exists as an empty string. When the two disagree, you've found the blank line.

    Inputs and outputs

    Array - a socket-only input, per the pack's convention for arrays. Everything in the πŸ“‹ Array group refuses to let you paste a list into it; you wire a producer in (πŸ“‹ Array From Text, πŸ“‚ List Files, πŸ“‚ Read File, πŸ“‹ Array Filter).

    Count Empty - the one boolean, off by default, covered above.

    One output: Count (INT). It's the most portable value in the pack in practice - you can wire it into anything that takes an integer, use it as a loop bound with an index primitive, or print it to the console when you're debugging a pipeline that keeps coming up short.

    Honest caveat on that: ComfyUI has no native loop node, so "use the count as a loop bound" usually means you're driving an index by hand, or batching differently. The count's real job is the sanity check - the moment a batch stops producing, Count is the first thing you look at.

    Install

    Manager: Extensions β†’ Node Pack β†’ search "Honda Nodes" β†’ Install β†’ restart. Manual:

    cd ComfyUI/custom_nodes
    git clone --depth 1 https://github.com/Avaray/honda-nodes.git
    cd honda-nodes
    python install.py    # ComfyUI's python; Windows portable: ..\..\..\python_embeded\python.exe install.py
    

    The install.py run downloads jq and ime into honda-nodes/bin for the pack's JSON and metadata nodes. This node doesn't use them, so it'll count fine without them - but the pack does require ComfyUI 0.38.0+, since it's written entirely against the V3 schema.

    Common issues

    Off by one at the end. Count Empty, as above. If Length says 8 and your loop goes to 8, item 8 is likely a blank line.

    Count is 1 when you expected many. Your list is comma-separated, not newline-separated. Split it first with πŸ“‹ Array From Text.

    Count never updates. The node isn't running. ComfyUI only executes what's upstream of an output node, so a Length node feeding nothing produces nothing; give it a consumer, even just a preview.

    Category⚑️ Honda Nodes/πŸ“‹ Array

    Inputs (2)

    NameTypeDefaultDescription
    arraySTRINGNewline-separated array string.
    count_emptyBOOLEANfalseIf disabled, empty lines are not counted.

    Outputs (1)

    NameTypeDescription
    CountINTβ€”