Pages

Monday, February 18, 2013

IE Array indexOf() - resolved

    /* 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)

No comments: