How can i add an entry to a specific index in a list?

前端 未结 4 856
天涯浪人
天涯浪人 2021-01-11 13:09

I can call list.add() which adds at the end but there is no convenient way to add an entry to a specific index which at the same time grows the list.

4条回答
  •  天涯浪人
    2021-01-11 13:53

    You can use insertRange, it will grow the list when adding new elements.

    var list = ["1","3","4"];
    list.insertRange(0, 1, "0");
    list.insertRange(2, 1, "2");
    list.forEach((e) => print(e));
    

    You can try it out on the DartBoard here

提交回复
热议问题