if (!Array.prototype.indexOf) Array.prototype.indexOf = function (searchElement, fromIndex) 0); i < this.length; i++) if (this[i] === searchElement) return i; return -1; ;
Here’s a concise, useful piece regarding ES3 (ECMAScript 3) editing, focusing on a common pitfall and its solution: In ES3, there is no Array.prototype.forEach , map , filter , or reduce . Using them will break in older environments (e.g., IE8). Fix: Use a traditional for loop, or manually add the missing methods if you control the environment. es3 edit
// ES3-safe array iteration var arr = [1, 2, 3]; for (var i = 0; i < arr.length; i++) console.log(arr[i]); Here’s a concise
(since ES3 arrays don’t have it either): there is no Array.prototype.forEach