Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I have this error: Object doesn't support property or method 'forEach' for Internet Explorer?

I am Working on Javascript on a jenkins plugin using maven and I have this code:

   function arrayElements(element, index, array) 
     {
         var arrayPaths = element.split("\\");
         var projectSource = arrayPaths[2];
         var array = element.split("_");
         if (projectSource === global ) {             
             if (array[2]===filtro){
             document.getElementById("source").options.add(new Option(arrayPaths[3], element));
             }
         }
     }
    function fillCompiledSource(object, projects)
    {
        document.getElementById("source").innerHTML = "";        
        global = document.getElementById("branches").value;     
        projects.forEach(arrayElements)
    }
    var projects = new Array();</script><script>
    function fillCombo()
    {
         document.getElementById("source").innerHTML = "";
         global = document.getElementById("branches").value;     
         var array = document.getElementById("branches").value.split('/');
         global = array[1];
         projects.forEach(arrayElements)       
    }

This fail only in internet explorer and only when document Mode is IE8 standarts I don't know what is the reason and how I can resolve that..

Pd: The Internet explorer is 10

like image 962
davdomin Avatar asked Nov 20 '13 14:11

davdomin


People also ask

Does forEach work in Internet Explorer?

forEach() is actually working on IE11, just be careful on how you call it. querySelectorAll() is a method which return a NodeList. And on Internet Explorer, foreach() only works on Array objects. (It works with NodeList with ES6, not supported by IE11).

Does forEach work in IE11?

Open up IE 11 and you will find “Object doesn't support property or method 'forEach'” in the console. If you do some googling you will find a lot of responses on stackoverflow that include NodeList. prototype. forEach = Array.


1 Answers

Yeap, its because IE8 does not implement Array.forEach (neither many other more modern JS methods). If you need to work in IE8, you will have to shim it (see the compatibility section).

By the way, MDN has resources for most of the other unsupported methods too.

like image 109
Nikos Paraskevopoulos Avatar answered Oct 07 '22 21:10

Nikos Paraskevopoulos