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

I start with JSON that looks like this:
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:

// 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') {
	    // Now we found another so increment count.
	    else {
	// 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++)
			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"