Yuari
Documentation
Docs/Core functions/table.create

table.create

Creates a table preallocated for a number of entries, optionally filled with one value.

Syntax

table.create(count: number, value?: any) -> table

Parameters

ParameterTypeDescription
countnumberNumber of entries to reserve. Must not be negative.
valueanyOptional value assigned to indices 1..count.

Returns

TypeDescription
tableThe new table.

Description

When value is omitted the table is only preallocated and stays empty, matching Luau.

A negative count raises table.create: count must be non-negative.

Example

local zeros = table.create(5, 0)
print(#zeros, zeros[1])  -- 5  0

local rows = table.create(3)
print(#rows)             -- 0

Notes

  • table.create(n, {}) — Shares one table across all slots; build each row in a loop instead.