2

I have two arrays

var master= ["1","2","3"];
var arr = ["1","5"];

i wanted to check if arr contains any item from master. Based on SO post here i have the following code which only works with chrome

var found = arr.some(r => master.indexOf(r) >= 0);

however it does not work with IE11. IE11 throws error

JavaScript critical error at line 23, column 44 in https://localhost:44328/js/xxxx.js\n\nSCRIPT1002: Syntax error

I have also tried

 var found = arr.some(r => master.includes(r) >= 0);
Nico Diz
  • 1,484
  • 1
  • 7
  • 20
LP13
  • 30,567
  • 53
  • 217
  • 400

1 Answers1

4

You need to take a classic function, because IE 11 has only ES5, that means no arrow functions nor Array#includes.

var master= ["1", "2", "3"],
    arr = ["1", "5"],
    found = arr.some(function (r) { return master.indexOf(r) >= 0; });

console.log(found);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392