IE11 and JavaScript array.map()

JackTheKnife Source

I have run into problem under IE11. It throws an error

Expected: ":"

for that line of code:

this.aAttachments = MessageStore.message().attachments().map(({fileName,mimeType,fileType,fileNameExt,download}) => [fileName,mimeType,fileType,fileNameExt,download]);

in the part

{fileName,mimeType,fileType,fileNameExt,download}

instead of commas.

Documentation says that IE support fully map since IE9

Any clue on that?

javascriptarraysinternet-explorerinternet-explorer-11

Answers

answered 1 week ago obermillerk #1

I don't think the issue is with map, I think the issue is that you're using a shortcut for assigning object properties to their own variables in that part you specified. I believe this is a relatively new feature to javascript so likely not supported by IE since it seems to lag far behind. I would suggest changing your inline function to

(obj) => [obj.fileName,obj.mimeType,obj.fileType,obj.fileNameExt,obj.download]

and see if that fixes it.

EDIT: Some people are also saying that IE does not support arrow functions either, so make that

function(obj) { return [obj.fileName,obj.mimeType,obj.fileType,obj.fileNameExt,obj.download]; }

comments powered by Disqus