Code Responsible

Skip navigation

Array.indexOf in JavaScript not working in IE

Evil IEI recently tried to do an indexOf on a JavaScript array and realized it doesn’t work in Internet Explorer. Unfortunately IE doesn’t support this method for arrays. After searching online I found a solution from Pear Web that suggested an IE fix. It worked perfectly! All I had to do was add the code below after the Array.indexOf.

if(!Array.indexOf){
    Array.prototype.indexOf = function(obj){
        for(var i=0; i<this.length; i++){
            if(this[i]==obj){
                return i;
            }
    }
    return -1;
    }
}

41 Posts

Ryan Burgess

Ryan Burgess is a Manager, UI Engineering at Netflix in San Francisco, California. Previously at Evernote. Listen to Ryan on the Front End Happy Hour podcast. He's also the creator of SensesLost.com, an online-based arts and culture magazine that focuses on graffiti and tattoo art.

6 Responses to “Array.indexOf in JavaScript not working in IE”

Leave a Reply

Comment Form