Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get each element count / occurrences / frequency from a list

const arr = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4];
const counts = {};

for (const num of arr) {
  counts[num] = counts[num] ? counts[num] + 1 : 1;
}

console.log(counts[5], counts[2], counts[9], counts[4]);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular schematics tree 
Javascript :: Temporarily Edit Text on Any Website 
Javascript :: Serve JSON on a Specific Route 
Javascript :: Pausing setInterval when page/ browser is out of focus 
Javascript :: dynamically fill bootstrap card 
Javascript :: react modal scroll 2 overlapping components 
Javascript :: empty donut chart chart js 
Javascript :: Replacing Specific word from url, replacing url 
Javascript :: javascript make variable 
Javascript :: nvm install a particular version 
Javascript :: jquery hide elevateZoom 
Javascript :: mreact graph 
Javascript :: repeat a block as many times as a nember jsx 
Javascript :: filewatcher nodejs 
Javascript :: on click a button triger a tab bootstrap 5 
Javascript :: Array.find Shorthand javascript 
Javascript :: sequelize autocomplete vscode 
Javascript :: Node-Red: 2Outputs 
Javascript :: JavaScript call url many times 
Javascript :: cpprestsdk json 
Javascript :: service erstellen angular 
Javascript :: appolo query data in angular graphql 
Javascript :: fiffo in javascript 
Javascript :: javascript grow function 
Javascript :: how do i make http post in nodejs without third party 
Javascript :: crear un texto dinamicamente con javascript 
Javascript :: js set array relation 
Javascript :: api dfetch data in reactjs 
Javascript :: Adding Notices in the Block Editor Wordpress 
Javascript :: pass js variable to css animation 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =