This is quite a common thing. The code itself is stored and executed as-is, but the variable i that it references is the same one each time - and it changes.
The usual solution for this is to use forEach to iterate over the array - it means that a new function is called for each menu item. That function will then have an argument i which is different for each call.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
This is quite a common thing. The code itself is stored and executed as-is, but the variable
i
that it references is the same one each time - and it changes.The usual solution for this is to use
forEach
to iterate over the array - it means that a new function is called for each menu item. That function will then have an argumenti
which is different for each call.Hope that helps!