Skip to content

Commit 383194b

Browse files
committed
Document table.findkey/findindex
1 parent 6f714d9 commit 383194b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

docs/Runtime Environment/Table.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ assert(table.contains(t, "nothing") == nil)
7272
```
7373
---
7474
### `table.find`
75-
Looks for an element in a table.
75+
Search a table for an element, returning its value.
7676
#### Parameters
7777
1. The table to check.
7878
2. The callback function responsible for checking each element.
@@ -87,6 +87,19 @@ local items = {
8787
print(items:find(|item| -> item.id == 1).name) --> Apple
8888
```
8989
---
90+
### `table.findkey`, `table.findindex`
91+
Search a table for an element, returning its key/index.
92+
#### Parameters
93+
1. The table to check.
94+
2. The callback function responsible for checking each element.
95+
#### Returns
96+
The key/index if found, otherwise `nil`.
97+
```pluto
98+
local fruit = { "apple", "banana", "orange" }
99+
print(fruit:findkey(|x| -> x == "banana")) --> 2
100+
print(fruit[2]) --> banana
101+
````
102+
---
90103
### `table.reverse`
91104
Reverses the array elements of a table.
92105
#### Parameters

0 commit comments

Comments
 (0)