title: Javascript Variable issue hitting multiple times
body: <pre><code> let data;
  
       if(post.images.some(img =&gt; img._id == doc_id)) {
          post.images.forEach(function(e,i){
            if (post.images[i]._id == doc_id) { 
               data = ..... // if i defined here const data then i know its block scope will be access within this block only
              let isData = false;
              if (data.length === post.images[i].data.length) {
                data.push(myId);
                isData = true;
              }
            post.images[i].data = data
  
            }
            })
       } else {
         data = ..... // if i defined here const data then i know its block scope will be access within this block only        let isData = false;
          if (data.length === post.data.length) {
            data.push(myId);
            isData = true;
          }
          post.data = data;
  
       }
  
       res.out(data)
  </code></pre>
  
  <p>Getting errror Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
  I know its getting problem from the loop i tried to fix with using return keyword but doesn't get success though. </p>
  
  <p>How can i fix this warning problem is there any other way to fix this please assist</p>