- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2022 08:00 PM
Hi There,
What does the "-1" mean in JavaScript? I have tried google but not getting much information back on it.
Here is a code snippet (example)
if(modDesc.indexOf("/knowledgebase.do?uri=kb_view.do?sys_kb_id") > -1){
modDesc = modDesc.split('/knowledgebase.do?uri=kb_view.do?sys_kb_id');
modDesc = modDesc.join('?id=kb_article&sys_id');
gs.print(gr[name] + ' - knowledgebase.do sys_kb_id links updated');
updated ++;
}
Thank you in advance for your help.
Ty
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-15-2022 08:05 PM
Hi
the JavaScript function indexOf() returns the position of a given String within another String. If nothing could be found, "-1" is returned. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf for more information.
Regarding your example it means, that only in case "/knowledgebase.do?uri=kb_view.do?sys_kb_id" is contained within the variable modDesc the code within the if condition is executed.
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2022 03:43 AM
Agree, should be replaced with var as below:
var index = str.indexOf(substr, [, fromIndex]);
Regards,
Shloke
Regards,
Shloke