logo
Search
showing results for - "counting instances of values in an object"
Niklas
05 Apr 2016
1let names = ['Alice', 'Bob', 'Tiff', 'Bruce', 'Alice']
2
3let countedNames = names.reduce(function (allNames, name) {
4  if (name in allNames) {
5    allNames[name]++
6  }
7  else {
8    allNames[name] = 1
9  }
10  return allNames
11}, {})
12// countedNames is:
13// { 'Alice': 2, 'Bob': 1, 'Tiff': 1, 'Bruce': 1 }
14
source
similar questions
how do i count the number of occurrences in a string javascriptjs obj getting count of propertiesjavacript count propertiescan we find lenght of an objectget amount of items in object jshow to know property count in js objectjs get number of keys in objectcount number of times an element is occuring in an array in javascriptjavascript get length of objectjavascript get number of elements in objectjavascript count instances in stringjs add count of object to keyjs count keys in objectjavascript count elements in json objectjavascript count number of occurrences in array of objectsjavascript count instances of character in a stringhow to count occurences in an array with javascriptnumber of properties in object javascriptfind a single element in array of objects javascript
queries leading to this page
count of object valuecounting numbers with objectscounting in objectscounting instances of values in an objectjavascript count occurences in objectcounting instances of values in an object
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue