Home number of times that condition is true [javascript]
Reply: 0

number of times that condition is true [javascript]

user946
1#
user946 Published in April 26, 2018, 5:21 pm

This is probably a really noob question. I tried to search but probably i´m not asking google the right words.

What i want to get is the number of times that the:

-number 3 exist

-number 2 exist

-number 43 exist

I could do it manually if the array has a fixed values, but the problem is that the array will be changing a lot, with completely different numbers.

i will leave a img here if the text is not explicit enough :D

var a = [2,3,3,3,2,43];
var t = [...new Set(a)];

for ( var k = 0, l = t.length; k < l; k ++ ) {
	for ( var i = 0, l = a.length; i < l; i ++ ) {
	
		if (a[i] == t[k]) {
	
		console.log(k);		
	}
};

};

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302888 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO