Array.prototype.indexOf() - JavaScript | json indexof
indexOf()wasaddedtotheECMA-262standardinthe5thedition;assuchitmaynotbepresentinallbrowsers.Youcanworkaroundthisbyutilizingthefollowingcodeatthebeginningofyourscripts.ThiswillallowyoutouseindexOf()whenthereisstillnonativesupport.ThisalgorithmmatchestheonespecifiedinECMA-262,5thedition,assumingTypeError(en-US)[1]andMath.abs()[2]havetheiroriginalvalues.if(!Array.prototype.indexOf){Array.prototype.indexOf=functionindexOf(member,startFrom){if(this==null){thrownewTypeError("Array.prototype.indexOf...
indexOf() was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all browsers. You can work around this by utilizing the following code at the beginning of your scripts. This will allow you to use indexOf() when there is still no native support. This algorithm matches the one specified in ECMA-262, 5th edition, assuming TypeError (en-US)[1] and Math.abs()[2] have their original values.
if (!Array.prototype.indexOf) { Array.prototype.indexOf = function indexOf(member, startFrom) { if (this == null) { throw new TypeError("Array.prototype.indexOf() - cant convert `" + this + "` to object"); } var index = isFinite(startFrom) ? Math.floor(startFrom) : 0, that = this instanceof Object ? this : new Object(this), length = isFinite(that.length) ? Math.floor(that.length) : 0; if (index >= length) { return -1; } if (index < 0) { index = Math.max(length + index, 0); } if (me...