title: Checking and deleting multiple occurrences of the same value in an array using javascript
body: <p>This is what I've been trying, but something is wrong with the last part, can sy please tell me whats wrong, or show me an other method of doing this. Thanks in advance.</p>
  
  <pre><code>function removeSpaces(string) {
    var str = string.replace(/^\s*|\s*$/g,'')
    str = str.replace(/[^a-z|A-z|\r\n]/g,'');
    while (str.indexOf("\r\n\r\n") &gt;= 0) {
      str = str.replace(/\r\n\r\n/g, "\r\n");
    }
    words = str.split("\r\n");
    var i = 0;
    var j = 0;
    for (i = 0; i &lt; words.length; i++) {
      for (j = i; j &lt; words.length; j++) {
        if ((i != j) &amp;&amp; (words[i] == words[j])) {
          words.splice(j,1);
          j--;
        }
      }
    }
    str = words.join("\r\n");
    return str;
  }
  </code></pre>