Find()
THE-Spellchecker154 total contributions
Published Dec 30, 2023Updated May 15, 2024
Contribute to Docs
The find() function is used to search for a specific value in a table and returns its index if found. The function returns nil
if the value is not present in the table.
Syntax
table.find(myTable,value)
myTable
: A table containing values where the specified value being searched is present.value
: This represents parameter of the value being sought after in the table.
Example
In this example, a table containing strings of letters is declared, and the table.find()
function is utilized to discover the index of a sought after value within the table. If not found, it will return nil instead.
-- Create a sample tablelocal myTable = {"a", "b", "c", "d", "e"}print(table.find(myTable, "d"))print(table.find(myTable, "j"))
This example results in the following output:
4nil
All contributors
- THE-Spellchecker154 total contributions
- moha2305 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.