WoW:API pairs: Difference between revisions
Jump to navigation
Jump to search
(Change category from "LUA Functions" to "Lua functions".) |
|||
| (6 intermediate revisions by 6 users not shown) | |||
| Line 1: | Line 1: | ||
{{wowlua}} | |||
Returns an iterator triple that allows for loops to iterate over all key/value pairs in a table. | |||
iteratorFunc, table, startState = pairs(table); | |||
== Example == | |||
local random_array = { mug = "coffee", [42] = "universe", testboolean = false } | |||
Example | |||
for index,value in pairs(random_array) do | |||
local random_array = { mug = "coffee", [42] = "universe", | |||
for index,value in pairs( | |||
if (type(index) == "number") then | if (type(index) == "number") then | ||
index = tostring(index) | index = tostring(index) | ||
| Line 24: | Line 23: | ||
mug : coffee | mug : coffee | ||
42 : universe | 42 : universe | ||
testboolean : false | |||
would be output to the chat window. | would be output to the chat window. | ||
Latest revision as of 04:46, 15 August 2023
← WoW Lua
Returns an iterator triple that allows for loops to iterate over all key/value pairs in a table.
iteratorFunc, table, startState = pairs(table);
Example
local random_array = { mug = "coffee", [42] = "universe", testboolean = false }
for index,value in pairs(random_array) do
if (type(index) == "number") then
index = tostring(index)
elseif (type(index) == "boolean") then
if (index) then
index = "true"
else
index = "false"
end
end
DEFAULT_CHAT_FRAME:AddMessage(index.." : "..value)
end
Result:
mug : coffee 42 : universe testboolean : false
would be output to the chat window.