Count instances of each unique item in an array

This is a script I wrote for Google Apps Scripts:

function oreGon(){
var arr = [ 1, 1, 1, 1, 1, 1, 1, 3, 3, 1, 4, 9, 1, 2, 0, 7, 8, 1, 2 ];
arr.sort();
var uniques = [];
var instCount = [];
var prev = 666;
var arrCount = arr.length;
for(var a = 0; a < arrCount; a++){
if (arr[a] !== prev ) {uniques.push(arr[a]); instCount.push(1)}
else {instCount[instCount.length-1]++}
var prev = arr[a];}
Logger.log(uniques)
Logger.log(instCount)
}