title: How to remove an event listener using forEach
body: <p>How do I remove an event listener after creating an event listener in a forEach loop? The forEach loop runs immediately and the conditional I have to determine whether the event should be removed is ran immediately.</p>
  
  <pre><code>function play(){
      let arr = document.querySelectorAll(".box");
      let remove = false;
      arr.forEach((value,index)=&gt; {
          value.addEventListener("click", () =&gt; {
              remove = true;
          });
      }
      if(remove === true){
          arr.forEach((value, index)=&gt;{
              value.removeEventListener("click", ()=&gt;{
  
              });
              })
          }
      }
  </code></pre>