What does (xxxx > -1) mean in a script?

User657785
Tera Contributor

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

1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi @Tyrone 

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

View solution in original post

5 REPLIES 5

Agree, should be replaced with var as below:

var index = str.indexOf(substr, [, fromIndex]);

 

Regards,

Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke