local example = {
["John"] = 5,
["Jane"] = 6
}
print(example ["John"])-- 5
How would I get it to return the actual string key instead of the keys value?
local example = {
["John"] = 5,
["Jane"] = 6
}
print(example ["John"])-- 5
How would I get it to return the actual string key instead of the keys value?
For cases like this I create an array of the dictionary’s keys. If you don’t have some kind of reference value then you won’t be able to get the key itself through direct indexing.
local function collectKeys(dictionary)
local keys = {}
for key, _ in pairs(dictionary) do
table.insert(keys, key)
end
return keys
end
I could then pick out what I want from there.