Table <BadgeShared/>
The Table module extends Lua's native table capabilities by adding powerful utility functions for enhanced table manipulation.
Table Functions > table.addMultiLevels()
<!-- @include: ./slots/headers.md#shared|table.addMultiLevels -->
A function to add a multiples table levels inside a variable if it not exists <br>
<!-- @include: ./slots/descriptions.md#shared|table.addMultiLevels -->
Table Functions > table.addMultiLevels() > Syntax
table.addMultiLevels(...)
Table Functions > table.addMultiLevels() > Parameters
... : table|string
if the 1st argument is a table, keys will be injected in it. Else, a new table will be created
Table Functions > table.addMultiLevels() > Return Value
Type : table
The new table with multiples table levels
<!-- @include: ./slots/examples.md#shared|table.addMultiLevels -->
<!-- @include: ./slots/footers.md#shared|table.addMultiLevels -->
Table Functions > table.clearForNui()
<!-- @include: ./slots/headers.md#shared|table.clearForNui -->
Returns a copy of the table with all function values removed. <br>
<!-- @include: ./slots/descriptions.md#shared|table.clearForNui -->
Table Functions > table.clearForNui() > Syntax
table.clearForNui(t)
Table Functions > table.clearForNui() > Parameters
t : table
The table to clean
Table Functions > table.clearForNui() > Return Value
Type : table
The table without function values
<!-- @include: ./slots/examples.md#shared|table.clearForNui -->
<!-- @include: ./slots/footers.md#shared|table.clearForNui -->
Table Functions > table.copy()
<!-- @include: ./slots/headers.md#shared|table.copy -->
Deep copies a table. Unlike "=", it doesn't keep the link between both tables. <br>
<!-- @include: ./slots/descriptions.md#shared|table.copy -->
Table Functions > table.copy() > Syntax
table.copy(t)
Table Functions > table.copy() > Parameters
t : table
The table you want to copy
Table Functions > table.copy() > Return Value
Type : table
The copy of the table
<!-- @include: ./slots/examples.md#shared|table.copy -->
<!-- @include: ./slots/footers.md#shared|table.copy -->
Table Functions > table.count()
<!-- @include: ./slots/headers.md#shared|table.count -->
Counts the number of values inside a table. <br>
<!-- @include: ./slots/descriptions.md#shared|table.count -->
Table Functions > table.count() > Syntax
table.count(t)
Table Functions > table.count() > Parameters
t : table
The table to count elements in
Table Functions > table.count() > Return Value
Type : integer
The number of values inside the table
<!-- @include: ./slots/examples.md#shared|table.count -->
<!-- @include: ./slots/footers.md#shared|table.count -->
Table Functions > table.deleteAndClear()
<!-- @include: ./slots/headers.md#shared|table.deleteAndClear -->
A function to delete a deep value in a table and clear the table if it's empty <br>
<!-- @include: ./slots/descriptions.md#shared|table.deleteAndClear -->
Table Functions > table.deleteAndClear() > Syntax
table.deleteAndClear(t, keys)
Table Functions > table.deleteAndClear() > Parameters
t : table
The table
keys : any
The keys to deep
Table Functions > table.deleteAndClear() > Return Value
Type : boolean
Returns
trueif the value was deleted
<!-- @include: ./slots/examples.md#shared|table.deleteAndClear -->
<!-- @include: ./slots/footers.md#shared|table.deleteAndClear -->
Table Functions > table.deleteDeepValue()
<!-- @include: ./slots/headers.md#shared|table.deleteDeepValue -->
A function to delete a deep value in a table <br>
<!-- @include: ./slots/descriptions.md#shared|table.deleteDeepValue -->
Table Functions > table.deleteDeepValue() > Syntax
table.deleteDeepValue(t, keys)
Table Functions > table.deleteDeepValue() > Parameters
t : table
The table
keys : any
The keys to deep
Table Functions > table.deleteDeepValue() > Return Value
Type : table,
<!-- @include: ./slots/examples.md#shared|table.deleteDeepValue -->
<!-- @include: ./slots/footers.md#shared|table.deleteDeepValue -->
Table Functions > table.doesKeyExist()
<!-- @include: ./slots/headers.md#shared|table.doesKeyExist -->
A function to know if a deep key exists in a table <br>
<!-- @include: ./slots/descriptions.md#shared|table.doesKeyExist -->
Table Functions > table.doesKeyExist() > Syntax
table.doesKeyExist(t, ...)
Table Functions > table.doesKeyExist() > Parameters
t : table
The table to check
... : string
The list of keys to deep
Table Functions > table.doesKeyExist() > Return Value
Type : boolean,
<!-- @include: ./slots/examples.md#shared|table.doesKeyExist -->
<!-- @include: ./slots/footers.md#shared|table.doesKeyExist -->
Table Functions > table.extract()
<!-- @include: ./slots/headers.md#shared|table.extract -->
Extracts a value from a table by key and removes that key from the table. <br>
<!-- @include: ./slots/descriptions.md#shared|table.extract -->
Table Functions > table.extract() > Syntax
table.extract(t, key)
Table Functions > table.extract() > Parameters
t : table
The table to extract from
key : any
The key to extract
Table Functions > table.extract() > Return Value
Type : any
The extracted value
<!-- @include: ./slots/examples.md#shared|table.extract -->
<!-- @include: ./slots/footers.md#shared|table.extract -->
Table Functions > table.filter()
<!-- @include: ./slots/headers.md#shared|table.filter -->
Filters a table based on a callback function. <br>
<!-- @include: ./slots/descriptions.md#shared|table.filter -->
Table Functions > table.filter() > Syntax
table.filter(t, filterIter, keepKeyAssociation)
Table Functions > table.filter() > Parameters
t : table
The table to filter
filterIter : function
A function to execute for each element in the table. Should return
trueto keep the element. Called with (element, key, originalTable)
keepKeyAssociation : boolean <BadgeOptional />
Keep the original table keys instead of creating a sequential table <br> default:
false
Table Functions > table.filter() > Return Value
Type : table
The filtered table
<!-- @include: ./slots/examples.md#shared|table.filter -->
<!-- @include: ./slots/footers.md#shared|table.filter -->
Table Functions > table.find()
<!-- @include: ./slots/headers.md#shared|table.find -->
Returns the first element in the table that satisfies the provided function. <br>
<!-- @include: ./slots/descriptions.md#shared|table.find -->
Table Functions > table.find() > Syntax
table.find(t, func)
Table Functions > table.find() > Parameters
t : table
The table to search in
func : function
A function to test each element. Should return
truewhen found. Called with (element, key, originalTable)
Table Functions > table.find() > Return Value
Type : any,any
The found value or
falseif not found , The key of the found value
<!-- @include: ./slots/examples.md#shared|table.find -->
<!-- @include: ./slots/footers.md#shared|table.find -->
Table Functions > table.getDeep()
<!-- @include: ./slots/headers.md#shared|table.getDeep -->
A function to get a deep value in a table <br>
<!-- @include: ./slots/descriptions.md#shared|table.getDeep -->
Table Functions > table.getDeep() > Syntax
table.getDeep(t, keys)
Table Functions > table.getDeep() > Parameters
t : table
The table
keys : any
The keys to deep
Table Functions > table.getDeep() > Return Value
Type : any,
<!-- @include: ./slots/examples.md#shared|table.getDeep -->
<!-- @include: ./slots/footers.md#shared|table.getDeep -->
Table Functions > table.includes()
<!-- @include: ./slots/headers.md#shared|table.includes -->
A function to search a value inside an array <br>
<!-- @include: ./slots/descriptions.md#shared|table.includes -->
Table Functions > table.includes() > Syntax
table.includes(t, value, fromIndex)
Table Functions > table.includes() > Parameters
t : table
The table
value : any
The value to search
fromIndex : integer <BadgeOptional />
index at which to start searching <br> default:
1
Table Functions > table.includes() > Return Value
Type : integer
Returns the index of the found value or 0 if missing
<!-- @include: ./slots/examples.md#shared|table.includes -->
<!-- @include: ./slots/footers.md#shared|table.includes -->
Table Functions > table.isEgal()
<!-- @include: ./slots/headers.md#shared|table.isEgal -->
Compares two tables for equality. <br>
<!-- @include: ./slots/descriptions.md#shared|table.isEgal -->
Table Functions > table.isEgal() > Syntax
table.isEgal(table1, table2, strict, canMissInTable1, canMissInTable2)
Table Functions > table.isEgal() > Parameters
table1 : table
First table to compare
table2 : table
Second table to compare
strict : boolean <BadgeOptional />
If all keys should be in both tables <br> default:
true
canMissInTable1 : boolean <BadgeOptional />
If table2 keys can miss in table1 <br> default:
false
canMissInTable2 : boolean <BadgeOptional />
If table1 keys can miss in table2 <br> default:
false
Table Functions > table.isEgal() > Return Value
Type : boolean
Returns
trueif tables are equal according to specified parameters
<!-- @include: ./slots/examples.md#shared|table.isEgal -->
<!-- @include: ./slots/footers.md#shared|table.isEgal -->
Table Functions > table.isEmpty()
<!-- @include: ./slots/headers.md#shared|table.isEmpty -->
Checks if a table is empty. <br>
<!-- @include: ./slots/descriptions.md#shared|table.isEmpty -->
Table Functions > table.isEmpty() > Syntax
table.isEmpty(t)
Table Functions > table.isEmpty() > Parameters
t : table
The table to check
Table Functions > table.isEmpty() > Return Value
Type : boolean
Returns true if the table is empty
<!-- @include: ./slots/examples.md#shared|table.isEmpty -->
<!-- @include: ./slots/footers.md#shared|table.isEmpty -->
Table Functions > table.map()
<!-- @include: ./slots/headers.md#shared|table.map -->
Creates a new table populated with the results of calling a function on every element. <br>
<!-- @include: ./slots/descriptions.md#shared|table.map -->
Table Functions > table.map() > Syntax
table.map(t, func)
Table Functions > table.map() > Parameters
t : table
The table to map
func : function|any
A function to transform each element. Called with (element, key, originalTable)
Table Functions > table.map() > Return Value
Type : table
The new mapped table
<!-- @include: ./slots/examples.md#shared|table.map -->
<!-- @include: ./slots/footers.md#shared|table.map -->
Table Functions > table.merge()
<!-- @include: ./slots/headers.md#shared|table.merge -->
Merges multiple tables together. <br>
<!-- @include: ./slots/descriptions.md#shared|table.merge -->
Table Functions > table.merge() > Syntax
table.merge(deepMerge, ...)
Table Functions > table.merge() > Parameters
deepMerge : boolean <BadgeOptional />
Whether to deep merge tables
... : table
The tables to merge
Table Functions > table.merge() > Return Value
Type : table
The merged table. If the same key exists in both tables, only the value of t2 is kept
<!-- @include: ./slots/examples.md#shared|table.merge -->
<!-- @include: ./slots/footers.md#shared|table.merge -->
Table Functions > table.mergeAfter()
<!-- @include: ./slots/headers.md#shared|table.mergeAfter -->
Merges the values of the second table sequentially into the first table. <br>
<!-- @include: ./slots/descriptions.md#shared|table.mergeAfter -->
Table Functions > table.mergeAfter() > Syntax
table.mergeAfter(...)
Table Functions > table.mergeAfter() > Parameters
... : table
The tables to merge
Table Functions > table.mergeAfter() > Return Value
Type : table
The merged table with values from t2 added at the end of t1
<!-- @include: ./slots/examples.md#shared|table.mergeAfter -->
<!-- @include: ./slots/footers.md#shared|table.mergeAfter -->
Table Functions > table.slice()
<!-- @include: ./slots/headers.md#shared|table.slice -->
Get a part of table with stard and end index <br>
<!-- @include: ./slots/descriptions.md#shared|table.slice -->
Table Functions > table.slice() > Syntax
table.slice(t, s, e)
Table Functions > table.slice() > Parameters
t : table
The table to get from
s : integer <BadgeOptional />
The start intex <br> default:
1
e : integer <BadgeOptional />
The end index <br> default:
s
Table Functions > table.slice() > Return Value
Type : table
The extracted table
<!-- @include: ./slots/examples.md#shared|table.slice -->
<!-- @include: ./slots/footers.md#shared|table.slice -->
Table Functions > table.upsert()
<!-- @include: ./slots/headers.md#shared|table.upsert -->
A function to set/update a value in a table with multiple levels <br>
<!-- @include: ./slots/descriptions.md#shared|table.upsert -->
Table Functions > table.upsert() > Syntax
table.upsert(...)
Table Functions > table.upsert() > Parameters
... : table|string
if the 1st argument is a table, keys will be injected in it. Else, a new table will be created. The last argument is the value to set
Table Functions > table.upsert() > Return Value
Type : table
The new table with multiples table levels
<!-- @include: ./slots/examples.md#shared|table.upsert -->
<!-- @include: ./slots/footers.md#shared|table.upsert -->