Skip to content

Instantly share code, notes, and snippets.

@Patrick-web
Created April 27, 2021 20:30
Show Gist options
  • Save Patrick-web/09c511a8d7a96a571c507ea92249cf15 to your computer and use it in GitHub Desktop.
Save Patrick-web/09c511a8d7a96a571c507ea92249cf15 to your computer and use it in GitHub Desktop.
A snippet for getting the number of times each item in an array has been repeated
uniqueCount = [
"a",
"b",
"c",
"d",
"d",
"e",
"a",
"b",
"c",
"f",
"g",
"h",
"h",
"h",
"e",
"a",
];
var count = {};
uniqueCount.forEach(function (i) {
count[i] = (count[i] || 0) + 1;
});
console.log(count);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment