Can you insert a value into a table into a position greater than (#table+1)?

I would like to know if you can insert a value into a table position greater than the number of values in that table plus 1.

for instance, in a table that has only 3 pre-existing values, can you insert a string into position 1000?:

local foodtable = {"French Fries", "Sandwich", "Apple"}

table.insert(foodtable,1000, "Hamburger")

Haven’t found any topics on this yet, anything would benefit! :sunglasses:

I’m not sure why you’d want to insert a value more than what the table has, however you can do it by setting it like it’s a dictionary, foodtable[1000] = "Hamburger"

2 Likes

table.insert(foodtable,1000, "Hamburger") will indeed work aswell

2 Likes

Ah, I was assuming it wouldn’t work with my answer as it seemed like they had tested it haha

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.