Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error using => in IE [duplicate]

Tags:

javascript

I have the following line of javascript code

var res = Object.keys(packages).filter(e => packages[e] === true)

The above works well in all the other browser apart from IE. IE complains about Syntax erro at => can someone tell me how to get around this in IE

like image 574
Izzy Avatar asked Mar 09 '23 21:03

Izzy


1 Answers

IE must not support arrow-functions. Just use the old function keyword.

.filter(function(e){ return packages[e] === true })

Side note, but you could also probably write this as:

.filter(function(e){ return packages[e] })

Unless packages[e] must actually be exactly equal to true and not just truthy.

like image 98
Carcigenicate Avatar answered Mar 19 '23 09:03

Carcigenicate