What is the difference between indexing with brackets vs periods because you get the same output
local Table = {["a"] = 3}
print(Table["a"]) -- 3
print(Table.a) -- 3
What is the difference between indexing with brackets vs periods because you get the same output
local Table = {["a"] = 3}
print(Table["a"]) -- 3
print(Table.a) -- 3
There isn’t really much of a difference, but there are differences where brackets can be used in special ways, such as using Instances as keys:
local TestTable = {}
TestTable[workspace] = 50
print(TestTable[game:GetService("Workspace")]) -- Prints 50
Without brackets:
local TestTable = {}
TestTable.workspace = 50
print(TestTable[game:GetService("Workspace")]) -- Prints nil
You must use brackets when indexing a key/field which isn’t a string value.