glarkou
glarkou

Reputation: 7101

Array.map not working in IE9

I am trying to built a websocket application in IE9 but I have the following Javascript error:

IE9 Console:

SCRIPT438: Object doesn't support property or method 'map' 
websock.js, line 211 character 5

websock.js function:

function send_string(str) {
    //Util.Debug(">> send_string: " + str);
    api.send(str.split('').map(
        function (chr) { return chr.charCodeAt(0); } ) );
}

Also in IE9 console str = the text I entered. and if I try to split it first then I get the correct array of the string but still map is not working.

For example if I try to send "text":

str.split("") = ['t','e','x','t']

And I found this in the console. But unfortunately .map is not working. Any suggestions?

PS:

I tried to change the w3school code this link:

document.write(str.split("").map(
        function (chr) { return chr.charCodeAt(0); } ) + "<br />");

And map is working here with the desirable result using IE9!

Upvotes: 4

Views: 7905

Answers (3)

Mathias Bynens
Mathias Bynens

Reputation: 149534

According to the ES5 compatibility table, IE9 does support Array#map. Visit http://kangax.github.com/es5-compat-table/ and look in the “This Browser” column.

Make sure the browser is in IE9 mode.

Upvotes: 0

sinsedrix
sinsedrix

Reputation: 4775

FF implements map:

Array.prototype.hasOwnProperty('map') // true

IE doesn't implement map:

Array.prototype.hasOwnProperty('map') // false

Sorry, it seems you'll have to code your own map function.

Upvotes: -1

ustun
ustun

Reputation: 7021

IE9 supports map, but most possibly your html page is rendered in quirks mode, that's why. Try adding a doctype, and see if that solves the problem.

Upvotes: 3

Related Questions