IE8 Object doesn’t support property or method ‘map’

One function that I used very frequently in Functional Programming language like F# is map. For C# I can use Select function in LINQ to do the same thing. With ECMAScript5, JavaScript also comes with built-in map function.

Here are how map functions looks like in JavaScript:

var sqrt = function(x){ return x*x;};
var numbers = [1,2,3];
var squares = numbers.map(sqrt);
// squares is [1,4,9]

However, if you still have to support IE8, unfortunately, it doesn’t support map function.

To make IE8 supports the map function, you can add a Polyfill that you can find on this page. Or if you use either jQuery or Lo-Dash, you can use jQuery.map or _.map as well.

// jQuery
var squares = jQuery.map(numbers, sqrt);

// Lo-Dash
var squares = _.map(numbers, sqrt);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s