WoW:API getn: Difference between revisions
Jump to navigation
Jump to search
m
no edit summary
No edit summary |
mNo edit summary |
||
| Line 22: | Line 22: | ||
3 | 3 | ||
getn and the # operator start at index [1] and count up, ceasing when they reach a nil value. This means that if you have a table | |||
t = { [0] = "zero", --will not be counted | |||
[1] = "one", --will be counted; 1 | |||
[2] = "two", --will be counted; 2 | |||
[3] = "three", --will be counted; 3 | |||
["four"] = "four", --will not be counted; returns 3 | |||
[5] = "five" } --will never be reached | |||
running getn(t) or #t will return 3, not the expected 4. Although there are 4 indices, it will count to three, see that t[4] is a blank spot, and return with a count of three. It will never reach 5. Furthermore, keys such as t["four"] and array values less than 1 such as t[0] are not counted at all. | |||
== See Also == | == See Also == | ||