In Javascript, I\'m trying to take an initial array of number values and count the elements inside it. Ideally, the result would be two new arrays, the first specifying each
Try this:
Array.prototype.getItemCount = function(item) { var counts = {}; for(var i = 0; i< this.length; i++) { var num = this[i]; counts[num] = counts[num] ? counts[num]+1 : 1; } return counts[item] || 0; }