Insert

Insert[list, elem, n]
inserts elem at position n in list. If n is negative, the position is counted from the end.

Insert[expr, elem, {i, j, ...}]
inserts elem at position in expr.

Insert[expr, elem, {{i1, j1, ...}, {i2, j2, ...}, ...}]
inserts elem at several positions.

DetailsDetails

  • list can have any head, not necessarily List.
  • Insert works on SparseArray objects by effectively inserting into the corresponding ordinary lists.

ExamplesExamplesopen allclose all

Basic Examples (4)Basic Examples (4)

Insert to be at position :

In[1]:=
Click for copyable input
Out[1]=

Insert to be at position 2 from the end:

In[1]:=
Click for copyable input
Out[1]=

Insert at several positions:

In[1]:=
Click for copyable input
Out[1]=

Insert into a 2D array:

In[1]:=
Click for copyable input
Out[1]=
New in 1
New to Mathematica? Find your learning path »
Have a question? Ask support »