Array.prototype.find icon indicating copy to clipboard operation
Array.prototype.find copied to clipboard

Unable to execute Array.prototype.find in IE / Edge

Open jayudhandha opened this issue 6 years ago • 3 comments

Hi,

I am using this to solve my problem for IE / Edge that does not support Array.find()

Below is my piece of code that i am using in my angular directive to find the element from array.

var found = scope.data.find(function(element, i) {
    index = i;
    return element.id === testObj.id;
});

Here scope.data is my json array and testObj is some random json which contains required id.

I am getting below error in IE / Edge.

Object doesn't support property or method 'find'

Any help?

jayudhandha avatar Aug 08 '19 10:08 jayudhandha

How are you importing/requiring this module, and are you doing so before the rest of your application loads?

ljharb avatar Aug 09 '19 06:08 ljharb

@ljharb I am adding this dependency in bower.json. After that i am using it in my angular directive. Do i need to import this dependency in the directive.js code? If yes, Than how?

This directive is being loaded on some click event (I am using Array.prototype.find in link function)

jayudhandha avatar Aug 12 '19 06:08 jayudhandha

I'm not familiar with angular (and I'd suggest consuming deps from npm; bower's long since deprecated and dead). However, you need to load polyfills eagerly, before all other code in your application - not conditionally or on click.

ljharb avatar Aug 12 '19 06:08 ljharb