0
IndexOf()
Why is the output -1 https://sololearn.com/compiler-playground/cS7qCZUEdNaC/?ref=app
2 ответов
+ 3
Shivam Gupta ,
> the string method `indexOf()` returns the zero-based index of the first occurrence of a specified character or substring in a given string.
> we can also pass an `index value` as a second argument to define where the search should start from.
> the method returns `-1` if the passed value can not be found.
in your case the search is looking for an upper case "F". but this does not exist in the string. so `-1` will be returned.
if we search for "r", the result will be 5.