How does JavaScript realize loop detection of keystrokes?

problem description

I want to do loop detection on keys several times, such as using for loop to detect buttons three times, and each time I detect that the button is triggered, I will execute the specified function, such as I press the space (keyCode=32), then print 1 in the background, and press three times to print out three 1s.
but the problem I have now is that three 1s will pop up once, with the code as follows:

<html>
  <script type="text/javascript">
    for(let i=0;i<3;iPP){
        document.addEventListener("keydown",function(){
            var e = event || window.event || arguments.callee.caller.arguments[0];
            if(e.keyCode!=null&&e.keyCode==32){
                console.log("ok");
            }
        })
    }
  </script>
</html>

ask the boss to answer questions ~


just remove the for statement;


addEventListener executes three times to add three keystroke listening events to document, so there are three 1


for loops


arguments.callee.caller.arguments [0] seems to report an error on Firefox. Change the following to
about counting

(function(){
 var idx = 0; 
 document.addEventListener("keydown",function(e){
  var e = e || window.event ||event;
  if(e.keyCode&&e.keyCode==32){
    idxPP;
    console.log(idx);
  }
 });
})();
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e9958f-174b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e9958f-174b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?