I am trying to figure out how to loop through a LUA table and take the results of a field and enter them into a new table. In the sample code below I would like to get the phone value from each record and insert it into the new table phoneNumbers. I have tried several ways of doing this and basically I keep getting a table with no data.
I am not sure what I am missing, but I feel it has something to do with value.phone. Any help is appreciated!
local phoneNumbers = {}
local people = {
{
name = "Fred",
address = "16 Long Street",
phone = "123456"
},
{
name = "Wilma",
address = "16 Long Street",
phone = "123456"
},
{
name = "Barney",
address = "17 Long Street",
phone = "123457"
}
}
for index,data in ipairs(people) do
for key, value in pairs(data) do
--print('\t', key, value)
table.insert(phoneNumbers, 1, value.phone)
--phoneNumbers[1] = value.phone
end
end
forstatement. The info you want is indata.phone.