by @kodeazy

flutter How to get second smallest element from an array?

Home » flutter » flutter How to get second smallest element from an array?
  • With the help of sort() function we get the smallest element in array.
  • sort() function sorts the elements in Asc order.
  • By accessing the second index we get the smallest element in the array.
  • Below is the sample example.

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

    Output:

    2