Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js returns the number of true values there are in an array

//returns the number of true values there are in an array
function countTrue(arr) {
	return arr.filter(w => w === true).length;
}

console.log(countTrue([true, false, false, true, false]));//  2
console.log(countTrue([false, false, false, false]));//  0
console.log(countTrue([]));//  0
Comment

PREVIOUS NEXT
Code Example
Javascript :: add element into array 
Javascript :: chart.js how to aligns legend in the chart 
Javascript :: react keys 
Javascript :: how to go back one directory in git bash 
Javascript :: set interval 
Javascript :: async await promise all javascript 
Javascript :: change a variable outside a function js 
Javascript :: react-dom and babel cdn 
Javascript :: Scroll elementleft using js 
Javascript :: capitalize first carater js 
Javascript :: javascript particles js not working 
Javascript :: img tag in react 
Javascript :: log javascript 
Javascript :: javascript factorial of a number 
Javascript :: js log stack trace 
Javascript :: node map has value 
Javascript :: image file size in react-dropzone 
Javascript :: express cors specific origins 
Javascript :: how play audio js 
Javascript :: how to get updated data-value in jquery 
Javascript :: discord.js edit embed message 
Javascript :: fivem esx script 
Javascript :: javascript hello world program 
Javascript :: jquery add class to body 
Javascript :: javascript find in nested array 
Javascript :: NextJS + Material-UI - Warning: Prop className did not match 
Javascript :: upload files with angular 
Javascript :: javascript cancel scroll 
Javascript :: jsx babel webpack 
Javascript :: javascript update text in div 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =