title: Javascript compare items in one array
body: <p>Pardon my complete lack of javascript knowledge in advance, but I can't seem to find a good example of how to compare two arrays and create another array based the results.</p>
  
  <p>I am attempting to get a list of user accounts from a storage device (uses javascript and handles MOST functions ok), and compare them against a statically created list of "good" users.</p>
  
  <p>Using a switch statement works but I really do not like it, and I'm sure there is a much better way (userList is populated dynamically from the device when I query it):</p>
  
  <pre><code>for (userName = 0; userName &lt; userList.length; userName++) {
      switch (userList[userName]) {
      case 'someuser1':
              printf('Username: ' + userList[userName] + ' is good\n');
              break;
      case 'someuser2':
              printf('Username: ' + userList[userName] + ' is good\n');
              break;
      case 'someuser3':
              printf('Username: ' + userList[userName] + ' is good\n');
              break;
      default:
              printf('Username: ' + userList[userName] + ' is NOT good\n');
      } 
  }
  </code></pre>
  
  <p>I would like to create a third array of "bad users" and compare them against a new array of "good users", and "found users". I have started with:</p>
  
  <pre><code>var goodUsers = ["someuser1", "someuser2", "someuser3"];
  </code></pre>
  
  <p>However I can't figure out the right combination of multiple for loops, if statements, or otherwise to compare the two and give me an array of the "bad users" that I can loop through and perform actions against.</p>
  
  <p>Any help would be appreciated!</p>