I would like to delete specific positions in an array and also reduce the length of the array such that it doesn't contain an undefined position after the delete. I'm also iterating over the array.
I can imagine a brute-force solution which would iterate twice over the array, but I just thought I'd check and see if there's something easier out there.
Here's what I've got:
_.each(foo._events, function (eventGroup) {
var keys = _.keys(eventGroup);
_.each(keys, function (key) {
if (eventGroup[key].ctx.isClosed) {
delete eventGroup[key];
console.log("Deleting closed");
}
});
});
This leaves an undefined element in the slot, though.
I was exploring some of the options here: How do I remove a particular element from an array in JavaScript? but I suspect modifying the array's length while iterating over it might result in odd behavior? But maybe it's fine since I'm accessing by key -- even though the keys appear to be "0", "1", "2".