Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object doesn't support property or method 'forEach' IE 11

I have below snippet

data.forEach(function (row) {
var dataRow = [];

columns.forEach(function (column) {

dataRow.push(row[column].toString());
})

which is giving me error data.forEach(function (row) { .What should be alternate to this? How to resolve it?

like image 818
RAM Avatar asked Oct 27 '25 09:10

RAM


1 Answers

For anyone using document.querySelectorAll('..').forEach() and having this issue in IE 11 saying "forEach is not a function", I found a hack on reddit which worked nicely:

if (typeof NodeList.prototype.forEach !== 'function')  {
    NodeList.prototype.forEach = Array.prototype.forEach;
}

This works perfectly and is 3 lines of code instead of a polyfill.

@JoeTaras hinted at this in his answer (yes IE does have Array.forEach since IE9), but I still think my answer adds value and will help other users.

like image 71
Yes Barry Avatar answered Oct 29 '25 22:10

Yes Barry