The documentation for indexOf on arrays already mentioned that the method returns -1 when the value is not found:
But for strings, this information was missing thus far:
Of course the user would have been able to puzzle this together by seeing that the return type is just number, not something like number | undefined, thus allowing them to figure out that the sentinel value probably must be -1. Nevertheless, having to stop and think about this is unnecessary friction for people who don't remember this fact by heart, for example people who jump between programming languages a lot.
I also noticed that the same information was missing for all the TypedArrays, so I went ahead and extended the docs there as well.
fixes #60570
The documentation for
indexOf
on arrays already mentioned that the method returns -1 when the value is not found:But for strings, this information was missing thus far:
Of course the user would have been able to puzzle this together by seeing that the return type is just
number
, not something likenumber | undefined
, thus allowing them to figure out that the sentinel value probably must be -1. Nevertheless, having to stop and think about this is unnecessary friction for people who don't remember this fact by heart, for example people who jump between programming languages a lot.I also noticed that the same information was missing for all the
TypedArray
s, so I went ahead and extended the docs there as well.