Garry's Mod Wiki

table.insert

  number table.insert( table tbl, number position, any value )

Description

Inserts a value into a table at the end of the table or at the given position.

This function does not call the __newindex metamethod.

Arguments

1 table tbl
The table to insert the variable into.
2 number position
The position in the table to insert the variable. If the third argument is nil this argument becomes the value to insert at the end of given table.
3 any value
The variable to insert into the table.

Returns

1 number
The index the object was placed at.

Example

Demonstrates the use of this function.

sentence = { "hello", "there", "my", "name", "is", "drakehawke" } table.insert( sentence, "lol" ) table.insert( sentence, 6, "not" ) PrintTable( sentence )
Output:
1 = hello 2 = there 3 = my 4 = name 5 = is 6 = not 7 = drakehawke 8 = lol