what does mean indexOf("searchString") == -1 this only for string or by alphabet also

Rajababu
Giga Guru

Hi ,

Can any one explain above term .

if indexOf("Gaurav") == -1 to indexOf("Gaurav") >-1 what it says

Line Gaurav is working in Servicenow or Servicenow working for gaurav or Every one knows gaurav working for Servicenow.

Can any one explain .nayan_awadhiya pradeepksharma

1 ACCEPTED SOLUTION

Gowrisankar Sat
Tera Guru

indexOf() refers to the Index where that particular string is found.



var string = testGaurav


Here: indexOf("Gaurav") returns 4.



var string = Gaurav


Here: indexOf("Gaurav") returns 0.



var string = testtest


Here: indexOf("Gaurav") returns -1, since the string is not found.



Which means, if string is found anywhere, it returns value starting from 0.


View solution in original post

11 REPLIES 11

Chuck Tomasi
Tera Patron

Any time you see string1.indexOf("string2") it is checking the position of "string2" in "string1". If it's not found, it returns -1 because 0 is the first position.


Hello Chuck,

Is there documentation on these string functions?

Thanks,

Chad

Here you go!

https://www.w3schools.com/jsref/jsref_indexof.asp

These are basic javascript functions.

Gowrisankar Sat
Tera Guru

indexOf() refers to the Index where that particular string is found.



var string = testGaurav


Here: indexOf("Gaurav") returns 4.



var string = Gaurav


Here: indexOf("Gaurav") returns 0.



var string = testtest


Here: indexOf("Gaurav") returns -1, since the string is not found.



Which means, if string is found anywhere, it returns value starting from 0.