Assigning array as a dictionary key

The title says it all. How can I assign an array as the key of a dictionary?

The same way you assign all other values:

local dictionary = {}
dictionary.key = {"value1", "value2", "value3"}

print(dictionary.key[2]) --value2

This is untrue. Basically anything can be a key in a dictionary.

local array = {"troll", "gaming", "nft"}

local dictionary = {

[array] = "hi",

[workspace] = "lol"

}

print(dictionary[array])

print(dictionary[workspace])

Oh, I am so sorry for spreading the wrong information, I was very unaware of this.
Thanks for correcting me.

1 Like

Im aware of assigning arrays like this:

t = {}

t[{"smth"}] = 1

However when i try to print it or access it, it returns nil. So the solution I’m doing rn is encoding it into JSON and reading it tht way, which is working fine. If I find any other more efficient methods, I might mark it as solution.

That’s because doing {“smth”} creates a new table every time, instead if you did

local tbl = {}
local smth = {"smth"}

tbl[smth] = 1
print(tbl[smth]) -- 1

The way to assign arr using string is

t = {}

t.Bob = 2

print(t.Bob) -- prints 2