title: Javascript algorithm to find elements in array that are not in another array
body: <p>I'm looking for a good algorithm to get all the elements in one array that are not elements in another array.  So given these arrays:</p>
  
  <pre><code>var x = ["a","b","c","t"];
  var ​​​​​​​​​y = [​​​​​​​"d","a","t","e","g"];
  </code></pre>
  
  <p>I want to end up with this array:</p>
  
  <pre><code>var z = ["d","e","g"];
  </code></pre>
  
  <p>I'm using jquery, so I can take advantage of <code>$.each()</code> and <code>$.inArray()</code>. Here's the solution I've come up with, but it seems like there should be a better way.</p>
  
  <pre><code>// goal is to get rid of values in y if they exist in x
  var x = ["a","b","c","t"];
  var y = ["d","a","t","e","g"];
  
  var z = [];
  $.each(y, function(idx, value){
    if ($.inArray(value,x) == -1) {
      z.push(value);
    }
  });
  ​alert(z);  // should be ["d","e","g"]
  </code></pre>
  
  <p>Here is the <a href="http://jsbin.com/axahi3/edit" rel="noreferrer">code in action</a>. Any ideas?</p>