loren schmidt
banner
lorenschmidt.bsky.social
loren schmidt
@lorenschmidt.bsky.social
i make art, mostly with computers. currently working on an open world RPG with roguelike roots and an experimental bent. cat mom. she / her or they / them.
i really like this, it's on this weird and pleasant list of js behaviors i love, like checking the string of a function name or object name, or looking up a function by name because it's a member of the window object.
November 11, 2025 at 6:48 PM
oh you can? i've not run into that! interesting.
November 11, 2025 at 6:44 PM
yeah it was supposed to have a hole! but it doesn't have undefined in it.

the solution was that i was getting a false positive in firefox, possibly there was no implementation difference, and for-of passes you undefined while for-in or .forEach() will not.
November 11, 2025 at 6:43 PM
i think the "correct" way would be to like, make an extra loop which finds out patch count, then make a bunch of empty objects ahead of time so there are no holes, then do this but i like this better.
November 11, 2025 at 6:33 PM
in this case, it's sort of using it as a dictionary for bookkeeping- because then you can ask if you've found a bin yet or not, and file data with it.

if (results[16] == undefined) {
// add data for 16
}
// outside block, modify that data (eg incrementing cell count)

actual code:
November 11, 2025 at 6:31 PM
oh sorry, i forked the replies. meant to reply here. i tested .foreach and it does indeed work in this case as well as for-in!
November 11, 2025 at 6:23 PM
and to confirm, .forEach() also works (tested 16x).
November 11, 2025 at 6:20 PM
ok i tried for-in. i tested 16 times and it did not throw any exceptions. i think the undefined properties are not iterable, so it's not virtualizing them and passing them to you as it does with a for-of loop.
November 11, 2025 at 6:16 PM
‪yeah i could either preformat or do
if (!undefined) {
// do current things
}

or switch to an iteration type which doesn't hand me undefined. out of curiosity i'll try for-in and .foreach()
November 11, 2025 at 6:06 PM
you can collapse and uncollapse the empty partitions of the debugger rendering, but they don't show anything.
November 11, 2025 at 6:03 PM
but one conceivable reason is that you can have really big holes in holey arrays, so showing the missing elements could make the array hard to read? but surely some indicator would be helpful!

for a concrete edge case, my unicode font sprites are a holey array on purpose and they look like this.
November 11, 2025 at 6:03 PM
so i'm deliberately leaning into the weirdness of js, and can only conjecture as to why normal programmers would set up either the language or the debugger this way.
November 11, 2025 at 6:03 PM
now that i'm testing more extensively in firefox, i am finding it does indeed throw an exception (depending on array particulars) sometimes. this is a few good runs, then an exception.

so probably the solution is to remove holes. unsure if there's any interesting browser specific behavior here.
November 11, 2025 at 5:56 PM
but this holey array of objects (which is different each run) can conceivably not be holey sometimes. so it can sometimes work fine /many/ times in a row, which was really confusing me. maybe it was just luck that it threw an exception more in chrome?
November 11, 2025 at 5:56 PM
yes, it is a holey array (on purpose), to clarify!

i have been working along these lines too, and i have some new info. (newer than the other reply thread.)

if i make a holey array of numbers, for-of will do an iteration with an undefined in both firefox and chrome. here is the result.
November 11, 2025 at 5:56 PM
oh maybe the dev tools, they definitely have moods in chrome.
November 11, 2025 at 5:45 PM
it helps so much! like for tuning the patch size or number of patches which are made into walls, i would have so much trouble without being able to see that step.
November 11, 2025 at 5:44 PM
so to clarify: it's a holey array, which firefox seems to sometimes handle fine in a for-of loop. the element 10 is missing here.

i currently have a bizarre test case which for-in iterates over an undefined for a holey array of numbers, but not for this holey object array. but browser specific.
November 11, 2025 at 5:44 PM
i use this iteration syntax a lot and i've never seen this before, it's weird.
November 11, 2025 at 5:07 PM
no, it's specific to the function and it's in a single threaded context. unless there's like, an antimalware extension or something injecting values?
November 11, 2025 at 5:07 PM