Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Lua 按特定索引从列表中删除项_Lua_Lua Table - Fatal编程技术网

Lua 按特定索引从列表中删除项

Lua 按特定索引从列表中删除项,lua,lua-table,Lua,Lua Table,我有这张桌子: local ls = { ["foo"] = {1, 2, 3, 4, 5}, ["bar"] = {5, 4, 3, 2, 1} } 我想从列表中删除“foo” 我试过这个: table.remove(ls, "foo") 但返回一个错误:“仅限数字” 好的,但我不能输入数字。这个列表不是静态的,在我的代码中,很多索引都会插入到这个列表中 问题是,是否有其他方法来执行此操作或其他功能,以满足我的问题?表。删除仅适用于序列。在代码中,表ls不是一个 要从表中删除条

我有这张桌子:

local ls = {
   ["foo"] = {1, 2, 3, 4, 5},
   ["bar"] = {5, 4, 3, 2, 1}
}
我想从列表中删除“foo”

我试过这个:

table.remove(ls, "foo")
但返回一个错误:“仅限数字”

好的,但我不能输入数字。这个列表不是静态的,在我的代码中,很多索引都会插入到这个列表中


问题是,是否有其他方法来执行此操作或其他功能,以满足我的问题?

表。删除仅适用于序列。在代码中,表
ls
不是一个

要从表中删除条目,只需将特定键的值指定给
nil

ls.foo = nil