Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check frequency of string in array js

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

for (var i = 0; i < arr.length; i++) {
  var num = arr[i];
  counts[num] = counts[num] ? counts[num] + 1 : 1;
}

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

PREVIOUS NEXT
Code Example
Javascript :: javascript remove last character 
Javascript :: how to check connected devices in react native 
Javascript :: window.history.pushstate typescript 
Javascript :: javascript code to loop through array 
Javascript :: How pass the token in ajax laravel 
Javascript :: jquery click event 
Javascript :: npm view available versions 
Javascript :: js is letter 
Javascript :: js canvas line end 
Javascript :: convert firestore timnestamp to javascript 
Javascript :: nodejs to exe 
Javascript :: how to check data type of javascript variable 
Javascript :: how to update node modules 
Javascript :: javascript download json 
Javascript :: box shadow javascript style change 
Javascript :: once page loaded run function 
Javascript :: split by whitespace javascript 
Javascript :: js replace non a-z 
Javascript :: document ready js 
Javascript :: value from getelementbyid 
Javascript :: javascript init an array to 0 
Javascript :: javascript removing smallest number in array 
Javascript :: return a boolean if a number is divisible by 10 javascript 
Javascript :: end code nodejs 
Javascript :: javascript restart video 
Javascript :: javascript array to csv string 
Javascript :: string reduction javascript 
Javascript :: javascript console input 
Javascript :: javascript generate random hex 
Javascript :: int to octal javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =