Reputation: 1417
I have an array of objects from which I need to find a particular index and then delete the corresponding object from the array.
I used the findIndex()
method :
var index = data.findIndex(x => x.OBJECTID == objectID);
data.splice(index, 1);
This works fine in Chrome but in IE 11, it throws
object doesn't support property or method 'findIndex'
I solved this by using the solution from this stackoverflow answer: findIndex() method issue with internet explorer
On inspecting the console log, I noticed a difference between the array of objects in Chrome and IE 11:
In IE 11, the console log, the array of objects is : enter image description here
while in Chrome, it's: enter image description here
Notice that the objects in Chrome are of type object but in IE, they're of type [object object]. Is that why the findIndex() method fails? If so, why is the type different and if not, why does the findIndex() fail in IE 11?
Upvotes: 0
Views: 6486
Reputation: 21845
If you use compilation for your project, you might consider to install polyfill package
npm i --save core-js
or
yarn add core-js
Then to add at the top of your entry point of your project
import 'core-js'
At the moment core-js polyfill library is the easiest way to make Cross Browser Support
Upvotes: 0
Reputation: 636
I believe your issue is not only findIndex, but also I.E. doesn't support lambda functions.
Using a for loop is inevitable for IE support. Or you can use lodash version of findIndex
var users = [
{ 'user': 'barney', 'active': false },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': true }
];
_.findIndex(users, function(o) { return o.user == 'barney'; });
Upvotes: 1