Skip to content

Instantly share code, notes, and snippets.

@JavaScript-Packer
Created July 1, 2015 01:25
Show Gist options
  • Save JavaScript-Packer/c48da237cc2e2a5baea7 to your computer and use it in GitHub Desktop.
Save JavaScript-Packer/c48da237cc2e2a5baea7 to your computer and use it in GitHub Desktop.
IE web browser often won't handle indexOf() command in JavaScript (Jscript is IE's engine or coding for Jscript.net), so here is an alternate function: http://jsfiddle.net/ccxqosxn/
function myIndexOf(a, b) {
var c, d, e = a.length, f = b.length;
for (c = 0; e > c; c++) {
for (d = 0; f > d && a[c + d] == b[d]; d++) ;
if (d == f) return c;
}
return -1;
}
//USAGE:
//var str1ng='http://www.WHAK.com';
//alert(myIndexOf(str1ng, 'WHAK'));
//-1 response means that it is not found in string
//returns character position that found is located
@JavaScript-Packer
Copy link
Author

Minified:

function myIndexOf(a,b){var c,d,e=a.length,f=b.length;for(c=0;e>c;c++){for(d=0;f>d&&a[c+d]==b[d];d++);if(d==f)return c}return-1}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment