So I write a short function to remove members from an object that have falsy values:
for (var key in object) {
if (!object[key]) {
delete object[key];
}
}
A couple days later I check source control and someone has changed this to:
var newObject = {};
for (var key in object) {
if (object[key]) { newObject[key] = object[key]; }
}
return newObject;
There's no comments on the check-in and the guy is not here today at work.
Which implementation is better? What are the performance implications of each method?