Yes, longer term some kind of API with an iterator (or given they're not really used in Espruino, a callback) might be really handy - but right now that's pretty low priority as you're basically the first person to have this problem in 10 years :)
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.
Yes, longer term some kind of API with an iterator (or given they're not really used in Espruino, a callback) might be really handy - but right now that's pretty low priority as you're basically the first person to have this problem in 10 years :)