title: javascript forEach manage exceptions
body: <p>I have a forEach loop that check if there are conditions before pushing data in the array:</p>
  
  <pre><code>allow(id, perm, arr) {
    const data = { "userId": id, "permissionId": perm };
  
    arr.forEach(key =&gt; {
      if (id !== key.userId) {
        throw new Error('id does not exists');
      } else {
        if (perm === key.permissionId) {
          throw new Error('perm exists in this id');
        } else {
          arr.push(data);
        }
      }
    });
  }
  </code></pre>
  
  <p>The original array <code>arr</code> is like this:</p>
  
  <pre><code>[{"userId": 1,"permissionId": 1},
   {"userId": 2,"permissionId": 1},
   {"userId": 3,"permissionId": 0},
   {"userId": 4,"permissionId": 0}]
  </code></pre>
  
  <p>if I use <code>console.log()</code> all works, but when I throw an error the execution stops, but how can I manage the exceptions without stop looping?</p>