jQuery + IE8 = Object doesn't support this property or method. How to fix this?

IE8 is giving me the following error:

Object doesn’t support this property or method on custom.js, line 82 character 7

  • Intercept page exit event
  • accessing a variable from window object in IE8 does not work
  • How to set cookies for two-letter domains in IE8?
  • onchange on radiobutton not working correctly in IE8
  • window.Event vs window.event
  • appendChild not working with window.open in IE
  • Here is the code with line numbers:

    78 function transpose(chord, increment){
    79   var scale = ["C", "C#", "D", "Es", "E", "F", "F#", "G", "As", "A", "B", "H"];
    80   return chord.replace(/[CDEFGABH]#?s?/g,
    81   function(match){
    82      var i = (scale.indexOf(match) + increment) % scale.length;
    83      return scale[ i < 0 ? i + scale.length : i ];
    84   });
    85 }
    

    What should I change so that the code works in IE8? It works properly in Firefox/Chrome and also in IE9.

  • Is there any onDocumentChange event?
  • MSIE Returns status code of 1223 for Ajax Request
  • Does IE 8 not support push?
  • why not use mouseup event target rather than position for “old school” drag-n-drop?
  • View JSON file in Browser
  • Any recommendation for IE 6 / 7 Javascript Memory Inspection tool?
  • One Solution collect form web for “jQuery + IE8 = Object doesn't support this property or method. How to fix this?”

    You can try a indexOf polyfill, this is needed due to indexOf being part of ECMAScript 5th Edition and thus not implemented by all browsers (actually just IE8 and lower).

    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
            "use strict";
            if (this === void 0 || this === null) {
                throw new TypeError();
            }
            var t = Object(this);
            var len = t.length >>> 0;
            if (len === 0) {
                return -1;
            }
            var n = 0;
            if (arguments.length > 0) {
                n = Number(arguments[1]);
                if (n !== n) { // shortcut for verifying if it's NaN
                    n = 0;
                } else if (n !== 0 && n !== Infinity && n !== -Infinity) {
                    n = (n > 0 || -1) * Math.floor(Math.abs(n));
                }
            }
            if (n >= len) {
                return -1;
            }
            var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
            for (; k < len; k++) {
                if (k in t && t[k] === searchElement) {
                    return k;
                }
            }
            return -1;
        }
    }