遍历数组下标table
使用for循环遍历
t= {"a","b","c","d"}
for i =1,#t do
print(i,t[i])
end
执行结果
使用ipars遍历
t = { "a", "b", "c", "d" }
for i, j in ipairs(t) do
print(i, j)
end
i代表数字下标
j代表i下标中的元素
执行结果
遍历字符串下标table
使用pars遍历
t = {
apple = "a",
banana = "b"
}
for i, j in pairs(t) do
print(i, j)
end
执行结果
next函数
t = {
apple = "a",
banana = "b"
}
print(next(t))
print(next(t, "apple"))
print(next(t, "banana"))
评论区