title: How to remove duplicates from array - javascript
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/9673/remove-duplicates-from-array">Remove duplicates from array</a>  </p>
  </blockquote>
  
  
  
  <p>Could you please help me out. I have this piece of code..</p>
  
  <pre><code>   &lt;html&gt;
    &lt;head&gt;
    &lt;title&gt;test&lt;/title&gt;
    &lt;script&gt;
  
    var array = new Array();
  
    function insert(val){
    array[array.length]=val;
    }
  
    function show() {
    var string="";
    for(i = 0; i &lt; array.length; i++) {
    string =string+array[i]+' , ';
    }
    if(array.length &gt; 0)
   document.getElementById('result').innerHTML = string;
    }
  
    function removeDuplicateElement(arrayName)
              {
                  var newArray=new Array();
                  label:for(var i=0; i&lt;arrayName.length;i++ )
                  {   
                      for(var j=0; j&lt;newArray.length;j++ )
                      {
                          if(newArray[j]==arrayName[i]) 
                          continue label;
                      }
                      newArray[newArray.length] = arrayName[i];
                  }
                  return newArray;
                  document.getElementById('result1').innerHTML = newArray;
              }
    &lt;/script&gt;
  
    &lt;/head&gt;
  
    &lt;body&gt;
    &lt;h2&gt;Demo&lt;/h2&gt;
    &lt;form name="form1"&gt;
    &lt;input id="userinput" type="text" name="Input"/&gt;
    &lt;input type="button" Value="Add" onclick="insert(getElementById('userinput').value),show();"/&gt;
    &lt;input type="button" Value="Substract" onclick="removeDuplicateElement(array);"/&gt;
    &lt;/form&gt;
     &lt;textarea style="border:1px solid #B3B3B3; width:218px;" rows="2" cols="30" type="text"  id="result"&gt;&lt;/textarea&gt;
     &lt;textarea style="border:1px solid #B3B3B3; width:218px;" rows="2" cols="30" type="text"  id="result1"&gt;&lt;/textarea&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I was trying to implement the remove duplicate function I found on the internet without any success. (see below) What am I doing wrong?</p>
  
  <pre><code>function removeDuplicateElement(arrayName)
  {
    var newArray=new Array();
    label:for(var i=0; i&lt;arrayName.length;i++ )
    {  
        for(var j=0; j&lt;newArray.length;j++ )
        {
            if(newArray[j]==arrayName[i]) 
            continue label;
        }
        newArray[newArray.length] = arrayName[i];
    }
    return newArray;
  }
  </code></pre>
  
  <p>Thank you!</p>