Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

count occurence in array js

// The initial array we want to count occurences
var initial = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4];  

// The count array asked for
var count = Array.from(new Set(initial)).map(val => initial.filter(v => v === val).length);  

// Outputs [ 3, 5, 1, 1 ]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #count #occurence #array #js
ADD COMMENT
Topic
Name
9+8 =