Difference Between Tables and Dictionaries?

Hello Developers :wave:,

I need help understanding the difference between Tables and Dictionaries because they both seem the same to me. And what are some use cases of when to use Dictionaries? Any response is deeply appreciated! :grin:

1 Like

There is not much difference.
Maybe dictionary is easier to interpret by looking at it than tables, but that’s my observation.

I believe you’re looking for the difference between an array and a dictionary. Both are tables.

The values inside arrays are indexed with numbers (from 1 and counting up).

local Table = {"Hello", 5, true}

print(Table[1]) --> "Hello"
print(Table[2]) --> 5
print(Table[3]) --> true

The values in dictionaries are indexed with keys. Keys could be: strings, numbers, instances, etc.

local Dictionary = {Message = "Hello!", [game.Workspace] = 20, [5] = true}

print(Dictionary.Message) --> "Hello!"
print(Dictionary["Message"]) --> "Hello!"

print(Dictionary[game.Workspace]) --> 20
print(Dictionary[5]) --> true

As you can see, Message has two ways to be indexed. There’s not much difference between choosing between one of them, but I like to use the first way.

Questions are welcome!


Ok, thanks! It cleared it for me

1 Like