Loading content...
Table
Table helpers — deep copy, merge, filter / map / find, contains, keys / values, count.
Table helpers — deep copy, merge, filter / map / find, contains, keys / values, count.
lib.table covers the common table operations. Shared (client + server).
| Function | Returns | Description |
|---|---|---|
deepcopy(tbl) | table | Recursive clone (independent copy). |
contains(tbl, value) | boolean | Whether the array contains value. |
merge(target, ...) | table | Merge sources into target (mutates it). |
filter(tbl, fn) | table | New array of elements where fn is true. |
map(tbl, fn) | table | New array with fn applied to each element. |
find(tbl, fn) | any? | First element where fn is true, or nil. |
count(tbl) | number | Count all keys (incl. non-numeric). |
keys(tbl) / values(tbl) | table | All keys / all values, as an array. |
deepcopy(tbl)tablecontains(tbl, value)booleanvalue.merge(target, ...)tabletarget (mutates it).filter(tbl, fn)tablefn is true.map(tbl, fn)tablefn applied to each element.find(tbl, fn)any?fn is true, or nil.count(tbl)numberkeys(tbl) / values(tbl)tablelocal snapshot = lib.table.deepcopy(config)
local merged = lib.table.merge({}, defaults, userPrefs) -- non-destructive
local adults = lib.table.filter(players, function(p) return p.age >= 18 end)
local names = lib.table.map(players, function(p) return p.name end)
local jean = lib.table.find(players, function(p) return p.name == 'Jean' end)contains / filter / map / find iterate 1..#tbl — they ignore dictionary keys (use keys / values for those). merge mutates target — use merge({}, ...) for a non-destructive merge. deepcopy loops forever on circular tables and copies FiveM userdata by reference.