How to check if all values in array are false with TypeScript

2 Answers

0 votes
function arrAllValuesFalse(arr : any) : boolean {
  	return arr.every(element => element === false);
}

const arr = [false, false, false, false, false, false];

console.log(arrAllValuesFalse(arr)); 

console.log(arrAllValuesFalse([false, true, false, false, false]));


  
  
  
/*
run:
  
true
false
  
*/

 



answered May 10, 2022 by avibootz
0 votes
function arrAllValuesFalse(arr : any ) : boolean {
  	return arr.every(element => !element);
}

const arr = [false, false, false, false, false, false];

console.log(arrAllValuesFalse(arr)); 

console.log(arrAllValuesFalse([false, true, false, false, false, 12]));

console.log(arrAllValuesFalse([false, 0, false, 0, false, '']));

  
  
  
/*
run:
  
true
false
true
  
*/

 



answered May 10, 2022 by avibootz

Related questions

...