What is [] In a script

a.b is syntactic sugar (a nicer way to write something) for a["b"]. However using the . notation for indexing only works if the indexer is a valid identifier (i.e a legal variable name)

So this works:

local t = { v = 56 }
print(t.v)
print(t["v"])

But something like this won’t:

print(t.Cool Key)

because Cool Key is not a valid identifier. That is where [] comes in

1 Like