• Why is the index not replaced?

    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.

    tempArray.forEach(function(m, i) {
          if (m.finished == false)
            menuObjekt[m.machine] = function(){showSettings(m)};
          }
    });
    

    Hope that helps!

About

Avatar for Gordon @Gordon started