Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 861
MicroMan Avatar asked Jul 26 '16 16:07

MicroMan


People also ask

Does IE11 support arrow functions?

IE11 does not support the arrow notation for anonymous functions.

What does => stand for in JavaScript?

It's a new feature that introduced in ES6 and is called arrow function. The left part denotes the input of a function and the right part the output of that function.

How do you filter an element in an array?

One can use filter() function in JavaScript to filter the object array based on attributes. The filter() function will return a new array containing all the array elements that pass the given condition. If no elements pass the condition it returns an empty array.

What is filter function in ES6?

ES6 - Array Method filter() filter() method creates a new array with all elements that pass the test implemented by the provided function.


2 Answers

ie 11 not support arrow functions

try

var selectedRoles = vm.roles.filter(function(x) { return x.id === role.id; }); 
like image 166
Grundy Avatar answered Sep 29 '22 00:09

Grundy


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 }); 
like image 36
Pranav C Balan Avatar answered Sep 29 '22 00:09

Pranav C Balan