What's the appropiate Technique to create a Table?

Is there a performance difference between this techniques?

local Technique1 = {Key1 = "1", Key2 = "2"--[[[…]]]}
local Technique2 = {}
Technique2.Key1 = "1"
Technique2.key2 = "2"
--[[[⋮]]]

Thanks in advance.

The former option is faster but the impact is quite negligible.

Thank you, I will use the another technique then.

I usually use this method to add strings together or for easier Module usage

t = {}
t.key = "Player_"
t.fullKey = t.key..Player.UserId
-- Alternate:
t["fullKey"] = `{t.key}{Player.UserId}`

print(t.fullKey) -- Player_...

However, you arent able to do it with the other method:

t = {
    key = "Player_"
    fullKey = t.key..Player.UserId -- just doesnt work
    fullKey = t["key"]..Player.UserId -- nor this
}

So the Method may not seem like much, but It can help you a lot
So i wouldn’t exactly say its “negligible.”

Thank you, I also thought about that, and now I know that the first technique is better.

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