table/insert

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (Also menu state)
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=insert
 
|Parent=table
 
 
|Description=Inserts a value into a table at the end of the table or at the given position.
 
|Description=Inserts a value into a table at the end of the table or at the given position.
 
|Realm=Shared and Menu
 
|Realm=Shared and Menu
Line 14: Line 12:
 
|type=number
 
|type=number
 
|name=position
 
|name=position
|desc=The position in the table to insert the variable.
+
|desc=The position in the table to insert the variable. If the position is nil then the element will be add at the end of the table
 
|default=nil
 
|default=nil
 
}}
 
}}

Revision as of 20:24, 11 July 2019

 table.insert( )

Contents

Description

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

Arguments

table tbl

The table to insert the variable into.

Arguments

number position=nil

The position in the table to insert the variable. If the position is nil then the element will be add at the end of the table

Arguments

any value

The variable to insert into the table.

Returns

number

The index the object was placed at.

Examples

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
Personal tools
Navigation