title: How can I search two object arrays for matching properties and then add a property if a value is true
body: <p>I currently have my router posting JSON data to a server I wrote with all of the currently connected nodes. In that data, it shows the node name and node uptime.</p>
  
  <p>I am then pushing those connections to a database. Before storing I am checking a few things. I am first checking to see if a node that was online has gone offline since the last post, then if a node that is now connected has never been connected before and lastly if a node that has been connected is a continuation of its previous connection or if it bumped offline and then back online between posts.</p>
  
  <p>My current code to sort the routers into their categories looks like this (reqRouters is an array of the nodes coming in via the post requests and dbRouters is an array of all of the nodes stored in the database):</p>
  
  <pre><code>function splitRouters(reqRouters, dbRouters) {
  
      let offlineRouters = [];
      let onlineRouters = [];
      let newRouters = [];
      let allRouters = [];
  
      for(let dbRouter of dbRouters) {
        if(dbRouter.connected === true &amp;&amp; !reqRouters.some(reqRouter =&gt; 
        reqRouter.user === dbRouter.user)) {
            offlineRouters.push(dbRouter);
        }
      }       
  
      for(let reqRouter of reqRouters) {
          dbRouters.some(router =&gt; router.user === reqRouter.user) ? 
          onlineRouters.push(reqRouter) : newRouters.push(reqRouter);
      }   
  
      allRouters.push(offlineRouters);
      allRouters.push(onlineRouters);
      allRouters.push(newRouters);
  
      return allRouters;
  }
  </code></pre>
  
  <p>This works for splitting them up, but I would like to add a property of newConnection to the object going into the onlineRouters array if it has gone offline since the last time the data posted. I am storing an array in the DB of all of the new connections, so every time a new connection is establish I push a new Date() to the array.</p>
  
  <p>I compare them like so: <code>dbRouter.allConnections[dbRouter.allConnections.length - 1].getTime() + 10000 &lt; reqRouter.uptime.getTime()</code></p>
  
  <p>I give an extra 10 seconds to allow for any differences in time due to processing. If the router has gone offline then the number of milliseconds will be greater and I will know that the node went offline and back online.</p>
  
  <p>The difficulty I am having is in getting access to both the individual <code>dbRouter</code> &amp; <code>reqRouter</code> when <code>.user</code> is equal and modifying the object to add a property of <code>.newConnection</code> before pushing it to onlineRouters.</p>
  
  <p>I am using a conditional to check for that property in a different function and handling the storing process differently contingent upon that.</p>
  
  <p>Any thoughts are appreciated on solving that or making any other bits of my code more efficient.</p>
  
  <p>Thank you :) </p>