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

1 Answer

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

const arr = [null, null, null, null, null, null];

console.log(arrAllValuesNull(arr)); 

console.log(arrAllValuesNull([null, undefined, null, null, null]));
 

  
  
  
/*
run:
  
true
false
  
*/

 



answered May 10, 2022 by avibootz

Related questions

...