const counts = {};
const sampleArray = ['a', 'a', 'b', 'c'];
sampleArray.forEach(function (x) { counts[x] = (counts[x] || 0) + 1; });
console.log(counts)
More Related Contents:
- what happens when an item is deleted from a javascript array [duplicate]
- Concat two arrays But concat is not working
- How can I create a two dimensional array in JavaScript?
- How can I get the index of an object by its property in JavaScript?
- Splitting a JS array into N arrays
- How to sort numbers correctly with Array.sort()? [duplicate]
- Is reading the `length` property of an array really that expensive an operation in JavaScript?
- Sort Array by ISO 8601 date
- Javascript – convert array of arrays into array of objects with prefilled values
- How to combine an array in javascript
- Array() vs new Array()
- How do I remove an object from an array with JavaScript? [duplicate]
- How to check if array is empty or does not exist? [duplicate]
- How to check whether multiple values exist within an Javascript array
- Converting JSON object to CSV format in JavaScript
- Importing data from multiple csv files in D3
- jQuery UI autocomplete with item and id
- Finding out how many times an array element appears
- How to check if an array is empty or exists?
- Javascript Set vs. Array performance
- Generate permutations of JavaScript array [duplicate]
- Populate nested object from array?
- What is the concept of Array.map?
- How to correctly use axios params with arrays
- Transform Javascript Array into delimited String
- Find the shortest string in array
- Array.of vs “[ ]”. When to use Array.of over “[ ]”?
- Array.push return pushed value?
- Declare an array in TypeScript
- Array of object deep comparison with lodash