by @kodeazy

flutter How to insert element at first index of List in a dart file?

Home » flutter » flutter How to insert element at first index of List in a dart file?
  • In this blog we will discuss on how to insert element at first index of List
  • insert is the function required to add element at the desired index.
  • Below is the syntax.

    exampleArray.insert(index, element)
  • index - position of the element where to insert.
  • element- Actual element to insert.
  • Below is the sample program of inserting elements in a List at first index.

    void main() {
    List<int> exampleArray = [2, 3, 4];
    exampleArray.insert(0, 1);
    print(exampleArray);
    }

    Output:

    [1, 2, 3, 4]