Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if any item in array === x then return false

var array = [false,true,true,true,true];

I would like to return false if any item in array is false and only return true if all items are true. is there a fast way to do this with out all the boilerplate? in python i would use the "if is in" syntax.

like image 638
maumauy Avatar asked Nov 26 '25 05:11

maumauy


1 Answers

In your case you'd use the every() method. The method expects every return value in each iteration to evaluate to true so simply passing the current value, which all happen to be a booleans will suffice without any additional logic.

var array = [false, true, true, true, true].every(bool => bool);

console.log(array);
like image 96
Carl Edwards Avatar answered Nov 28 '25 19:11

Carl Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!