table.clear
Removes every key from a table in place.
Syntax
table.clear(t: table) -> nil
Parameters
| Parameter | Type | Description |
|---|---|---|
t | table | Table to empty. |
Returns
| Type | Description |
|---|---|
| - | No return value. |
Description
Array and hash keys are both removed, and the table identity is kept, so existing references see the empty table.
Use t = {} instead when you want to drop the old table rather than empty it.
Example
local cache = { a = 1, b = 2 }
table.clear(cache)
print(next(cache)) -- nil
Notes
table.clear(t)— Raises an error iftis not a table.