WoW:API pairs: Difference between revisions

48 bytes added ,  15 August 2023
m
Move page script moved page API pairs to WoW:API pairs without leaving a redirect
(fixed bug in in the example ("local random_array"..."pairs(fruits)"))
m (Move page script moved page API pairs to WoW:API pairs without leaving a redirect)
 
(5 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Native Lua statement:
{{wowlua}}
 
Returns an iterator triple that allows for loops to iterate over all key/value pairs in a table.
Used in loop constructs to iterate through the values of a table, with index beeing anything.
  iteratorFunc, table, startState = pairs(table);
 
Example:
 
  local random_array = { mug = "coffee", [42] = "universe", true = "false" }


== Example ==
local random_array = { mug = "coffee", [42] = "universe", testboolean = false }
  for index,value in pairs(random_array) do  
  for index,value in pairs(random_array) do  
   if (type(index) == "number") then
   if (type(index) == "number") then
Line 24: Line 23:
   mug : coffee
   mug : coffee
   42 : universe
   42 : universe
   true : false
   testboolean : false


would be output to the chat window.
would be output to the chat window.
{{LUA}}
Anonymous user