Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to keys/indexes work in tables?

Hi, if i were to set a key for a table which position would that key be placed in?. would be placed in the first position, last or a random one?. for example.

local myTable = {}
myTable[myKey] = " this is a key"

and can i set a key without giving it a value such as

local myTable = {}
myTable[myKey] 

3 comments

0

local myTable = { ["Key"] = "Table key"; } .

0

could you answer my questions?

0

You may want to accept my answer. :))

1 answer

✓ Accepted answer

Yes, it can, but you have to set it to "nil". Take this, as an example:

local table = {}
table["Key01"] = nil;
--^ The Key01 is the key, the value is stored in a "pair" of the Key01 and nil.

4 comments

0

thak you, and does it insert that key into the first available slot?. for example if my table had keys going from 1, 5 would it insert in the 6th position

0

This is not a table, this would be an array.

0

And yes, you can insert it like this.

0

thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.