Skip to content

Commit eeba736

Browse files
committed
docs for indexOf and includes
1 parent 448785d commit eeba736

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/Core__Array.resi

+30-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,36 @@ Console.log([{"language": "ReScript"}]->Array.includes({"language": "ReScript"})
228228
*/
229229
@send
230230
external includes: (array<'a>, 'a) => bool = "includes"
231-
@send external indexOf: (array<'a>, 'a) => int = "indexOf"
231+
232+
/**
233+
`indexOf(array, item)` returns the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.
234+
235+
Returns `-1` if the item doesn not exist. Check out `Array.indexOfOpt` for a version that returns `None` instead of `-1` if the item does not exist.
236+
237+
See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.
238+
239+
## Examples
240+
```rescript
241+
Console.log([1, 2]->Array.indexOf(2)) // 1
242+
Console.log([1, 2]->Array.indexOf(3)) // -1
243+
Console.log([{"language": "ReScript"}]->Array.indexOf({"language": "ReScript"})) // -1, because of strict equality
244+
```
245+
*/
246+
@send
247+
external indexOf: (array<'a>, 'a) => int = "indexOf"
248+
249+
/**
250+
`indexOfOpt(array, item)` returns an option of the index of the provided `item` in `array`. Uses [strict check for equality](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality) when comparing items.
251+
252+
See [`Array.indexOf`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf) on MDN.
253+
254+
## Examples
255+
```rescript
256+
Console.log([1, 2]->Array.indexOfOpt(2)) // Some(1)
257+
Console.log([1, 2]->Array.indexOfOpt(3)) // None
258+
Console.log([{"language": "ReScript"}]->Array.indexOfOpt({"language": "ReScript"})) // None, because of strict equality
259+
```
260+
*/
232261
let indexOfOpt: (array<'a>, 'a) => option<int>
233262
@send external indexOfFrom: (array<'a>, 'a, int) => int = "indexOf"
234263
@send external joinWith: (array<'a>, string) => string = "join"

0 commit comments

Comments
 (0)