Skip to content Skip to sidebar Skip to footer

Javascript Map Method Creating 'object Doesn't Support This Property Or Method ' In Internet Explorer (ie)?

javascript code shows error in Internet Explorer but not in FF. $(document).ready(function(){ var countries = [ ['Afghanistan','Af'], ['Ă…land Islands','Ax'], ['Zimbabw

Solution 1:

The Array.prototype.map() function is only supported in Internet Explorer 9, so that code won't work in earlier versions of the browser. Since you've tagged the question as jQuery, you could use the jQuery.map() function instead:

var countryNames = jQuery.map(countries, function(country) {
    return { 
        value: country[0]
    }
});

jsFiddle DEMO tested using Internet Explorer 9 in IE7 mode.

Solution 2:

Use Jquery .each() instead http://api.jquery.com/jQuery.each/

var countryNames = [];    
$.each(countries, function(index, value){
    countryNames.push(value[0]);
}

Solution 3:

Not all versions (if any) have Array.prototype.map

This is a polyfill/MonkeyPatch you can use to support it under IE -- but including this code may cause problems if you use for ... in on your arrays.

Array.prototype.map

Solution 4:

var my_var=countryNames();
}); 

should be:

}); 
  var my_var=countryNames;

Worked in IE9 for me.

Or you can you use $.each like Neil Kennedy said.

Post a Comment for "Javascript Map Method Creating 'object Doesn't Support This Property Or Method ' In Internet Explorer (ie)?"