finding the number of occurrences of same the string stored in a array of objects
<p>I was trying to aggregate the number of title names and from different title sources.
I was successful in removing duplicates from array of objects and display only original version of title from each source only single time with out any duplicates. But I have fallen short of showing the detail abt how many duplicates of each title names were there in the json. Like in here we have 4 from each. But I was unable to get the total duplicates. The part is the <code>else</code> condition of <code>ifExistFlag</code> that Ive added in the code.
I am also adding a fiddle link</p>

<p><a href="http://jsfiddle.net/wF4qX/5/" rel="nofollow">http://jsfiddle.net/wF4qX/5/</a></p>

<pre><code>  var inputJson = [{
      "Sources": [{
          "title": "Title Name",
          "source": "SourceName1",
          "date": "07-05-2013 00:38:40",
          "link": "Link to 1"
        }, {
          "title": "Title Name",
          "date": "07-05-2013 00:24:17",
          "source": "SourceName2",
          "link": "Link to 2"
        }
      ]
    }, {
      "Sources": [{
          "title": "Title Name",
          "source": "SourceName1",
          "date": "07-05-2013 00:38:40",
          "link": "Link to 1"
        }, {
          "title": "Title Name",
          "date": "07-05-2013 00:24:17",
          "source": "SourceName2",
          "link": "Link to 2"
        }
      ]
    }, {
      "Sources": [{
          "title": "Title Name",
          "source": "SourceName1",
          "date": "07-05-2013 00:38:40",
          "link": "Link to 1"
        }, {
          "title": "Title Name",
          "date": "07-05-2013 00:24:17",
          "source": "SourceName2",
          "link": "Link to 2"
        }
      ]
    }, {
      "Sources": [{
          "title": "Title Name",
          "source": "SourceName1",
          "date": "07-05-2013 00:38:40",
          "link": "Link to 1"
        }, {
          "title": "Title Name",
          "date": "07-05-2013 00:24:17",
          "source": "SourceName2",
          "link": "Link to 2"
        }
      ]
    }
  ]
   $(document).ready(function () {
    var sourceList = AggregateSource(inputJson);
    var sourcePrint = printFinalSourceData(sourceList);
    $("#output").html(sourcePrint);
  });



  function AggregateSource(sourceArray, number) {
    var l = {};
    var finalArray = [];
    for (var i = 0; i &lt; sourceArray.length; i++) {
      for (var j = 0; j &lt; sourceArray[i].Sources.length; j++) {
        if (l.hasOwnProperty(sourceArray[i].Sources[j].source) == false) {
          l[sourceArray[i].Sources[j].source] = [];
          var m = {};
          m["title"] = sourceArray[i].Sources[j].title;
          m["link"] = sourceArray[i].Sources[j].link;
          m["date"] = sourceArray[i].Sources[j].timeStamp;
          m["count"] = 1;
          l[sourceArray[i].Sources[j].source].push(m);
        } else {
          var ifExistFlag = true;
          for (var k = 0; k &lt; l[sourceArray[i].Sources[j].source].length; k++) {
            if (l[sourceArray[i].Sources[j].source][k]["title"] == sourceArray[i].Sources[j].title) {
              ifExistFlag = false;
            }
          }
          if (ifExistFlag == true) {
            m["title"] = sourceArray[i].Sources[j].title;
            m["date"] = sourceArray[i].Sources[j].timeStamp;
            m["link"] = sourceArray[i].Sources[j].link;
            l[sourceArray[i].Sources[j].source].push(m);
          } else {
            //  alert(l[sourceArray[i].Sources[j].source][j]["count"])
          }
        }
      }
    }
    finalArray.push(l);
    return finalArray;
  }



  function printFinalSourceData(inputArray) {
    var sourceHTML = '';
    for (var k = 0; k &lt; inputArray.length; k++) {
      for (key in inputArray[k]) {
        for (var i = 0; i &lt; inputArray[k][key].length; i++) {
          sourceHTML += "&lt;span style='width:80%; float:left; font-size:14px;'&gt;&lt;a href='" + inputArray[k][key][i].link + "' target='_blank' style='text-decoration:none; color:#333333; font-weight:bold;'&gt;" + inputArray[k][key][i].title + "&lt;/a&gt;&lt;/span&gt;&lt;br&gt;&lt;span style='width:80%;float:left; font-size:10px; color: #3f4041;'&gt;" + key.split("_").join(" "); + "&lt;/span&gt;&lt;br&gt;";
        }
      }
    }
    return sourceHTML;
  }
</code></pre>
