
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:49 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:54 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:52 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2020 09:43 AM
Hello Chuck,
Is there documentation on these string functions?
Thanks,
Chad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-21-2020 04:08 AM
Here you go!
https://www.w3schools.com/jsref/jsref_indexof.asp
These are basic javascript functions.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:54 AM
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.