How to Check Key Index or Value Exists on Array List in Flutter/Dart

In this example, you will learn how to check the Key index or value exists or not in Array List in Flutter or Dart. See the example below, we have shown an example to check key index or value in Array List.

List<String> countries = ["Nepal", "India", "Pakistan", "USA", "Canada", "China"];
if(countries.contains("Nepal")){
      //there is element
}else{
      //there is no element
} 

You can use array.contains(value) to check if a value exists in the array List or not. It will return TRUE if the value is there and FALSE if the value is not there.

List<String> countries = ["Nepal", "India", "Pakistan", "USA", "Canada", "China"];

if(countries.asMap().containsKey(4)){
    //if there is key, 
}else{
    //if there is not key
}

You can use array.asMap().containsKey(index)  to check if the Key index exists or not in Array List.

Check This also: How to get Index Key of Map or List Array by Value in Flutter/Dart

In this way, you can check if Array List has a Key index or value or not in Dart or Flutter. 

No any Comments on this Article


Please Wait...