New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
Every button I build inside a loop calls the same handler, and each one logs the same last number.
What you'll have at the end
A loop where each callback logs its own iteration number instead of the final one
You need
a loop that builds one button per item and wires up each button's handler inside that same loop
Not covered
keeping a captured index correct after several items get removed one after another, since a plain array position goes stale the moment an earlier row disappears and needs a stable id instead
Checked 21 Aug 2026
Part of the JavaScript cookbook