Return to Snippet

Revision: 45214
at April 27, 2011 13:12 by shabith


Updated Code
/* this will work in all browsers(no jQuery needed) */
if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
    return -1;
  }
}

//call
var i = haystack_array.indexOf("needle")




/* or you can use jquery instead */

//call
var i = jQuery.inArray("needle", haystack_array)

Revision: 45213
at April 27, 2011 13:11 by shabith


Updated Code
/* this will work in all browsers(no jQuery needed) */
if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
    return -1;
  }
}

//call
haystack_array.indexOf("needle")




/* or you can use jquery instead */

//call
jQuery.inArray("needle", haystack_array)

Revision: 45212
at April 27, 2011 13:11 by shabith


Initial Code
/* this will work in all browsers(no jQuery needed) */
if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
    return -1;
  }
}

//call
haystack_array.indexOf("needle")




/* or you can use jquery instead */
haystack_array.indexOf("needle");

//call
jQuery.inArray("needle", haystack_array)

Initial URL

                                

Initial Description
source: http://stellapower.net/content/javascript-support-and-arrayindexof-ie/<br>
source: http://www.robsearles.com/2010/03/11/ie-7-indexof-replacement/

Initial Title
IE7 Array indexOf() fix

Initial Tags
array, jquery

Initial Language
JavaScript