What is the List.any() method in Dart?

Overview

The any() method can be used to check if at least one item in a List satisfies the condition.

Syntax

bool any(bool test(E element));

Parameter

  • Element represents each item in the list.

Return type

  • Bool

Code

The following code shows how to use the any() method in dart:

void main(){
// Creating list
List numbers = [9, 5, 8, 17, 11, 15, 23];
// Using any()
// verify if at least one item in the list is greater than 7
if (numbers.any((item) => item > 7)) {
// Print result
print('At least one number > 7 in the list');
}
}
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources