table在删除元素时要注意,例
t = { "hello", "world", "!"}
t[1] = nil
此时print(#t) --输出3,就是说把表的元素置为nil并没有移除该表项。

但,若是:

t = {
[] = nil,
[] = ,
[] = nil
} function count(t)
local c =
for k, v in pairs(t) do
c = c +
end
return c
end print(count(t))--1

再看更诡异的

 t = {
[] = ,
[] = nil,
[] =
} function count(t)
local c =
for k, v in pairs(t) do
c = c +
end
return c
end print("------------------", #t)
t2 = { "hello", "world", "!"}
t2[] = nil
t2[] = nil
t2[] = nil
print("--------t2---------", #t2)
for k, v in pairs(t2) do
print(k, v)
end print("--------------->")
for i=, #t2 do
print(i, t2[i])
end

最新文章

  1. Android之实现ViewPagerIndicator
  2. [转载] Can't create table './store/#sql-b2c_1a.frm' (errno: 150)和sql execution error #1452添加外键时错误解决方法
  3. 让Session失效的三种方法
  4. Android应用插件式开发解决方法[转]
  5. ios8.1.2耗电情况严重的解决方法
  6. Mindset + Know-how+Concepture + Methodology+Technology
  7. windows下实现linux的远程访问以及linux上文件的上传和下载
  8. HDU - 1407 打表
  9. console.log 简写
  10. 关于查找iOS中App路径时所要注意的一个问题
  11. [ Servlet / JSP ] J2EE Web Application 中的 JSESSIONID 是什么?
  12. 将 ASP.NET Core 2.0 项目升级至 ASP.NET Core 2.1.3X
  13. Linux操作系统配置Go语言编程环境
  14. 链表(list)使用注意
  15. C# 实现Bezier曲线(vs2008)
  16. Star HDU1541
  17. Go语言中Socket通信TCP服务端
  18. Spark2 Dataset之collect_set与collect_list
  19. js 兼容各类手机 的写法 待续
  20. Readme.MD 例子

热门文章

  1. python模块之ConfigParser: 用python解析配置文件
  2. Eclipse CDT 配置C /C ++ 标准库 (UBUNTU 12 )
  3. 记c#中构造函数中this的用法
  4. Git Error: warning: refname 'origin/branch-name' is ambiguous.
  5. Cause: org.postgresql.util.PSQLException: ERROR: cached plan must not change result type的前因后果
  6. 【转】Linux下同时复制多个文件
  7. Struts2自定义标签3模仿原有的s:if s:elseif s:else自定义自己的if elsif else
  8. ballerina 学习二十 http/https
  9. leetcode:Insert Sort List
  10. python删除x天前文件及文件夹