title: Get all unique values in a JavaScript array (remove duplicates)
body: <p>I have an array of numbers that I need to make sure are unique. I found the code snippet below on the internet and it works great until the array has a zero in it. I found <a href="https://stackoverflow.com/questions/1890203">this other script</a> here on Stack Overflow that looks almost exactly like it, but it doesn't fail.</p>
  
  <p>So for the sake of helping me learn, can someone help me determine where the prototype script is going wrong?</p>
  
  <pre><code>Array.prototype.getUnique = function() {
   var o = {}, a = [], i, e;
   for (i = 0; e = this[i]; i++) {o[e] = 1};
   for (e in o) {a.push (e)};
   return a;
  }
  </code></pre>
  
  <h3>More answers from duplicate question:</h3>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/9229645">Remove duplicate values from JS array</a></li>
  </ul>
  
  <h3>Similar question:</h3>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/840781">Get all non-unique values (i.e.: duplicate/more than one occurrence) in an array</a></li>
  </ul>