3 ms·
On object looping: Object.keys(obj).forEach(function (key) { var value = obj[key]; // ... }); Not the best thing, but it works in less
by strager 15y ago
On object looping:
Object.keys(obj).forEach(function (key) {
var value = obj[key];
// ...
});
Not the best thing, but it works in less lines than:
var key;
for (key in obj) {
if (!Object.prototype.hasOwnProperty(obj, key) {
continue;
}
var value = obj[key];
// ...
}
Plus, it avoids the async-function-in-a-loop problem (which is why I rarely use C-style `for` loops or `for-in` loops now).