Skip to content

Instantly share code, notes, and snippets.

@bladerunner2020
Created March 13, 2019 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bladerunner2020/35b76ef82778b9a426653ec59a974116 to your computer and use it in GitHub Desktop.
Save bladerunner2020/35b76ef82778b9a426653ec59a974116 to your computer and use it in GitHub Desktop.
Implementation of Array.indexOf for Iridium Mobile
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(searchElement, fromIndex) {
var k;
if (this == null) {
throw new TypeError('"this" is null or not defined');
}
var O = Object(this);
var len = O.length >>> 0;
if (len === 0) {
return -1;
}
var n = +fromIndex || 0;
if (Math.abs(n) === Infinity) {
n = 0;
}
if (n >= len) {
return -1;
}
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
while (k < len) {
if (k in O && O[k] === searchElement) {
return k;
}
k++;
}
return -1;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment