I have created this little interaction for one of the platforms at work - http://jsfiddle.net/S79qp/426/
It works fine in all browsers apart form IE8. When I run the console it seems to be this section that it is having problems with...
Array.prototype.forEach.call(l, function(item) {
a.push(jQuery(item).text());
});
Can someone show me an IE8 friendly alternative so I can make it compatible for the versions required?
If all you want is forEach()
in IE8:
if (typeof Array.prototype.forEach != 'function') {
Array.prototype.forEach = function(callback){
for (var i = 0; i < this.length; i++){
callback.apply(this, [this[i], i, this]);
}
};
}
This will behave as expected in any browser that doesn't have it built-in.
Use the jQuery.each
method:
jQuery.each(l, function(index, item){
a.push(jQuery(item).text());
});
If the target array is empty from start, you can use the jQuery.map
method for this instead:
var a = jQuery.map(l, function(item){
return jQuery(item).text();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With