The primary issue causing the malfunction is that using {} signifies declaring an object, while using [] indicates declaring an array.
Aside from that, the code you provided requires only minimal adjustments.
var items = ['A', 'A', 'A', 'B', 'B', 'C'];
function count(items) {
var result = [];
var count = 0;
for (var i=0; i<items.length; i++) {
var item = items[i];
if(typeof result[item] === 'undefined') {
//this is the first time we have encountered this key
//so we initialize its count to 0
result[item] = 0;
}
result[item]++;
}
return result;
}
var result = count(items);
for (var key in result) {
alert(key + " : " + result[key]);
}