IE 11 Script1002 Array.Filter(x => ...) (Arrow functions)

JavascriptEcmascript 6Internet Explorer-11

Javascript Problem Overview


I get a error message in IE11 but not in chrome the error is:

> Script1002 Syntax error

My code is as follows

var selectedRoles = vm.roles.filter(x => x.id === role.id);

The line and column number of the error suggest that it is the arrow function => that IE11 does not like. However it works fine in Chrome and Edge

Javascript Solutions


Solution 1 - Javascript

ie 11 not support arrow functions

try

var selectedRoles = vm.roles.filter(function(x) { return x.id === role.id; });

Solution 2 - Javascript

IE not supported arrow function check browser compatibility here. If you want IE support then use the normal function instead.

var selectedRoles = vm.roles.filter(function(x) {
  return x.id === role.id
});

Solution 3 - Javascript

The arrow function is not supported yet in IE 11. You can refer to these compatibity table: https://kangax.github.io/compat-table/es6/ to get an overview what is suuported where and to what extent in a detailed fashion.

Use pollyfills or a PRE-ES6 compatible code, e.g.

var selectedRoles = vm.roles.filter(function(x) {
   return x.id === role.id
});

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMicroManView Question on Stackoverflow
Solution 1 - JavascriptGrundyView Answer on Stackoverflow
Solution 2 - JavascriptPranav C BalanView Answer on Stackoverflow
Solution 3 - JavascriptAyanView Answer on Stackoverflow