by @kodeazy

Flutter How to remove specific value from group of elements in array?

Home » flutter » Flutter How to remove specific value from group of elements in array?
  • I have a group of elements in an array as below.

    var example_array = [9, 9, 7, 6, 5, 4, 3, 2, 1];
  • By using removeWhere function we can remove desired element from group of elements in array.
  • To remove 9 from the array of elements below is the syntax

    example_array.removeWhere((element) => element == 9);
  • Below is the sample program on removing the elements.

    void main() {
    var example_array = [9, 9, 7, 6, 5, 4, 3, 2, 1];
    example_array.removeWhere((element) => element == 9);
    print(example_array);
    }

    Output:

    [7, 6, 5, 4, 3, 2, 1]