I have a table
{
['i']=0,
['o'] = 1
}
Can I get the index names rather than the index value?
Only get [index names] from tables
Started by EveryOS, Apr 13 2016 07:38 PM
3 replies to this topic
#1
Posted 13 April 2016 - 07:38 PM
#2
Posted 13 April 2016 - 07:44 PM
yes.
for i,v in pairs(tabl)
-- i is index
end
for i,v in pairs(tabl)
-- i is index
end
#4
Posted 13 April 2016 - 08:07 PM
You can save code:
function getIndex(tab, value)
local indexes = {}
for index, var in pairs(tab) do
if var == value then
table.insert(indexes, index)
end
end
return table.unpack(indexes)
end
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











