I would like to remove certain elements of the object (for the sake of argument, those whose keys begin with '_'). What an elegant way to do this? Naive way:
for (var i in obj) if (i[0] === '_') delete obj[i];
but this changes the underlying object during the iteration. In Node, at least I think I could
Object.keys(obj).forEach(function (i) { if (i[0] === '_') delete obj[i]; });
or restart the iteration every time something is deleted with an inconvenient nested loop.
Are there any better solutions?
EDIT: When testing just now, in node.js, at least the naive solution actually works. Of course, it is possible that for ... in (necessary) it is implemented safely. Somebody knows?
source share