I've tried to delete multiple entries in an array.
These entries are objects and I need to locate the object meeting specific criteria.
var pending = [];
a.forEach(function(entry, index) {
if(entry.b == data) {
pending.push(index);
}
});
pending.forEach(function(entry) {
a.splice(entry, 1);
});
The problem is that it only deletes half of what I want (when b = data) and even deletes some random entries...
Thank you for your help.
a, what isdata? What are you trying to keep, show us some relevant (albeit simplified) code, with variables filled in?splice(), the indexes inashift for everything> entry, so the nextentryis off by 1, next by 2, etc. Look into.filter()..filter(). It isn't a mutator like.splice(), so it won't altera. It instead creates a newArraywithout the filtered element that you can assign back intoaasa = a.filter(...);.