by @kodeazy

flutter how to check if an array contains specific value?

Home » flutter » flutter how to check if an array contains specific value?
  • I have a list of Integers in my dart file.
  • To check whether the list contains specific value we use contains method.
  • Below is the syntax.

    print(example_array.contains(7));
  • If the list contains 7 then prints true else prints false.
  • Below is the example code.

    import 'package:flutter/material.dart';
    void main() {
    var example_array = [9, 9, 7, 6, 5, 4, 3, 2, 1];
    print(example_array.contains(7));
    }

    Output:

    true