We use the any()
method to check if at least a single element in an array is true.
any(array)
array
: The array we want to check.
A boolean value is returned. If at least one element is true, then true
is returned. Otherwise, false
is returned.
// import std.stdioimport std.stdio;import std.algorithm;// main methodvoid main(string[] args) {// create arrayint[] array1 = [50, 20, 10, 45, 34];int[] array2 = [0, 0, 0, 0];int[] array3 = [false, false, true];string[] array4 = [];// check if elements are truewriteln(any(array1)); // truewriteln(any(array2)); // falsewriteln(any(array3)); // truewriteln(any(array4)); // false}
any()
method. Then, we print the values.