As the title says, I want to make something like this:
local tab = {
["Item1"] = "Sword";
["Item2"] = "Apple"
}
local expectedtab = {
"Sword";
"Apple"
}
Thanks whoever tried to help.
As the title says, I want to make something like this:
local tab = {
["Item1"] = "Sword";
["Item2"] = "Apple"
}
local expectedtab = {
"Sword";
"Apple"
}
Thanks whoever tried to help.
local tab = {
["Item1"] = "Sword";
["Item2"] = "Apple"
}
local expectedtab = {}
for _,v in pairs(tab) do
table.insert(expectedtab,v)
end
print(expectedtab)
Curious why you want to turn a dictionary into an array- you already get the Values when you loop through them.
But for future reference, you should be using table.create
to pre-allocate space for your new array so the code doesn’t have to resize the table each time you add a new index to it.
local Dictionary = {
["A"] = 1,
["B"] = 2
}
local Table = table.create(#Dictionary)
for Key, Value in next, Dictionary do
table.insert(Table, Value)
end
I just need a faster way to do something like “Sword, Apple”.
Both of the scripts work, thank you all!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.