title: Count occurrences of each number present in array using javascript
body: <p>I am trying to count number of occurrences of number present in array.<br/>
  <strong>Logic</strong> <br/>
  So I already have one array that contains numbers, so I want to push only unique numbers into another array. Also I have another array that contains <strong>Counts</strong> of each number. <br/></p>
  
  <p><strong>CODE :</strong><br/></p>
  
  <pre><code>&lt;html&gt;
     &lt;body&gt;
  
        &lt;script language="javascript" type="text/javascript"&gt;
           &lt;!--
            var numbers = [ 2, 1, 2, 1, 3, 4, 2];
            var count = [];
            var newNumbers = [];
  
            newNumbers[0] = numbers[0];
            count[0] = 1;
  
            for(var i = 1 ; i &lt; numbers.length ; i++){
                for(var j = 0 ; j &lt; newNumbers.length ; j++){
                    if(numbers[i] == newNumbers[j]){
                        document.write("&lt;br/&gt;" + "Number Already Present" + " " +numbers[i]);
                    count[j] = count[j]++;
  
                    }else{
                        newNumbers.push(numbers[i]);
                    }
                }
            }
             for(var j = 0 ; j &lt; newNumbers.length ; j++){
                 document.write(newNumbers[j]);
             }
           //--&gt;
        &lt;/script&gt;
  
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><br/>
  Please help !</p>