Yuari
Documentation
Docs/Core functions/table.clear

table.clear

Removes every key from a table in place.

Syntax

table.clear(t: table) -> nil

Parameters

ParameterTypeDescription
ttableTable to empty.

Returns

TypeDescription
-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 if t is not a table.