I want to count the total number of occurrences of each value.

I start with JSON that looks like this:
Code:
{
"peeps":[
	{"id":"I0","name":"Bob","group":7,"school":"LSU"},
	{"id":"I1","name":"John","group":7,"school":"FSU"},
	{"id":"I2","name":"Tim","group":6,"school":"UNLV"},
	{"id":"I3","name":"Carl","group":3,"school":"UNC"},
	{"id":"I4","name":"John","group":6,"school":"LSU"},
	{"id":"I5","name":"Bob","group":5,"school":"LSU"},
	{"id":"I6","name":"John","group":6,"school":"UNC"},
	]
}
Through a drop-down box a user selects a field (name, group, school, etc). Based on that field, I want to call a function that returns the count of each unique occurrence. For example, if name is selected it would return an object or array with an ordinal index, the unique value, and total count. It must be an ordinal index.

Here is my current function:

Code:
// Pass JSON object and selected field name to count
function countFields(data,fieldName) {

	var Unique = []; // store unique values
	var Counts = []; // store occurences of each vbalue
	
    // Look at values in data.peeps
	for(var i in data.peeps)
	{
	    // Set index equal to value
	    var Index = data.peeps[i][fieldName];
	    
	    // Add value to Unique
	    Unique[Index] = data.peeps[i][fieldName];
	    
	    // Found the first occurence of a value
	    if(typeof(Counts[Index])=='undefined') {
	        Counts[Index]=1;
	    }
	    // Now we found another so increment count.
	    else {
	        Counts[Index]++;
	    }
	}
	
	// remove empty items
	Unique = Unique.filter(function(){ return true});
	Counts = Counts.filter(function(){ return true});
	
	var a=[];
	
	for(var i=0; i<Unique.length; i++)
	{
	    a.push({
			
			id: Unique[i],
			count: Counts[i]
		});
	}
	
	return a;
}
This seems to work if group is selected since it's an integer value.

console.dir(a) shows:
Object {id=7, count=2}
Object {id=6, count=3}
Object {id=3, count=1}
Object {id=1, count=1}

The problem is when I select any other non-integer field (name, etc). I only get "There are no child objects"