Javascript - Unique values in array count

var d = [1B, 1B, 0A, 2A, 0A, 2A, 0A];

var distances = {}d.each(function(e,i){distances[e]= (distances[e] || 0) + 1;});

distances = {0A: 3, 1B: 2, 2A: 2};