Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the javascript .map() function supported in IE8?

When doing this:

var a = new Array("a", "b"); a.map(function() { }); 

in IE8 I get:

"Object doesn't support this property or method" 

Is this method not supported in IE8, or do I have some other problem? I've had a Google, but get lots of Google Maps javascript issues/questions...

Edit: OK so IE8 and below DO NOT support the .map() function. Copy-paste the code from MDN here which will add the .map() function to the Array prototype exactly per the specs if not natively supported (and it seems to work perfectly).

like image 411
Richard H Avatar asked Sep 08 '11 15:09

Richard H


People also ask

Does map work on arrays?

Generally map() method is used to iterate over an array and calling function on every element of array. Parameters: This method accepts two parameters as mentioned above and described below: function(currentValue, index, arr): It is required parameter and it runs on each element of array.

What is the use of map () in JavaScript?

map() creates a new array from calling a function for every array element. map() calls a function once for each element in an array.

Is JavaScript map supported in IE?

The last version of the Maps JavaScript API to support Internet Explorer 11 is v3. 47. Support for Internet Explorer 11 will be entirely discontinued in November 2022. This also applies to the IE mode in Edge.


2 Answers

The solution is jQuery.map

Instead of this: a.map(function( ) { });

You have to do

jQuery.map(a, function( ) { //what ever you want todo .. }

like image 107
Interactive Tribe Avatar answered Oct 06 '22 20:10

Interactive Tribe


IE8 doesn't support map(). When in doubt, check MDN (Mozilla Developer Network):

map - MDN

Looks like IE added support for map() in version 9.

like image 43
Justin Niessner Avatar answered Oct 06 '22 21:10

Justin Niessner