创建
t = {} 空表
t = {“11”,”22”,”33”}
print(t[1])
print(t[2])
print(t[3])
索引从 1 开始,没有返回 nil
t = {“11”,bb=”22”,”33”,d=44,[6]=”六六”,77}
print(t[1]) — “11” 索引为 1
print(t[2]) — “33” 索引为 2
索引计算会跳过 kv 型的元素递增
print(t[‘bb’])
print(t[‘d’])
key 在定义时不加引号,取值时需要引号
print(t.bb)
print(t.d)
kv元素支持 .xx 取值,数字索引不支持
操作
t1={11,22,aa=”AA”,33,44,55,a=66,b=77}
print(#t1)
长度为 5 , 只统计数字索引的元素
table.insert(t1,1,”one”)
插入
不指定索引,末尾添加
table.remove(t1,1)
不指定索引,末尾删除
table.sort(t1,排序规则)