Can I use table.find() to get values based on an index that's a string? (such as: ["Car"] = 10)

Pretty straight forward. How does one get a value from a table based on a named index?
(e.g. {[“Car”] = 10, [“Truck”] = 50}. I want to get the value from using the string “Truck”).

LoadedAnimations[Tool.Name] = {Equip = EquipAnimTrack, Idle = IdleAnimTrack}
-- (should be: '["Gun"] = {Equip = EquipAnimTrack, Idle = IdleAnimTrack})

local ToolAnimations = table.find(LoadedAnimations, Tool.Name)
-- I want to find the value based on the index name thing (["Gun"]) from the previous table

How does one achieve this?

Like this.

A custom table.find ig.

function findindex(tabler,val)
if tabler[val] ~= nil then
return true
else
return false
end
end

Might not work cuz wrote it on mobile

1 Like
local Dictionary = {
    Car = 10,
    ["Apple"] = 2
}

print(Dictionary.Apple)
print(Dictionary["Car"])

Is that what you mean?

oh im dumb. Completely forgot you can just try indexing with a string and then check if it has returned a value or not.

Thanks for that!