
- 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
‎05-19-2025 05:17 AM
Can we use any method alternative to indexOf() it's not working in my script im using this to fetch records in description field in assignment rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2025 04:21 PM
A code sample would be the best way to get some help on your issue.
What is the type of the item you are calling indexOf() on? What is the type of the item you are using as the argument for indexOf()? Are they JavaScript or Java? The best way is to ensure that you convert all items to JavaScript so you are consistent. You can also use the string function of search() which allows you to use a RegEx. Both return integers so if the string you are using as the argument is not found it will return -1 in both cases. Don't use any comparison operators on that result since there are 4 options you can use ( x >= 0, x > -1, x == -1, x < 0) that can be confusing. I suggest you use the ~ operator which will do a 2's compliment on the result so that a not found result will be 0 instead of -1 since ~-1 is 0. Go ahead and press F12 and try it in the console. Now you can put the ~indexOf() or ~search() in an if statement and utilize the toBoolean result.