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.stdio import std.stdio; import std.algorithm; // main method void main(string[] args) { // create array int[] array1 = [50, 20, 10, 45, 34]; int[] array2 = [0, 0, 0, 0]; int[] array3 = [false, false, true]; string[] array4 = []; // check if elements are true writeln(any(array1)); // true writeln(any(array2)); // false writeln(any(array3)); // true writeln(any(array4)); // false }
any()
method. Then, we print the values.RELATED TAGS
CONTRIBUTOR
View all Courses