3 ms·
You never had to use `hasOwnProperty()` to iterate a map. `Object.keys()` in conjunction with `Array.prototype.forEach()` works well for this. Example: var map
by jonpaul 12y ago
You never had to use `hasOwnProperty()` to iterate a map. `Object.keys()` in conjunction with `Array.prototype.forEach()` works well for this. Example:
var map = {a: '1', b: '2'}
Object.keys(map).forEach(function(k) {
console.log(map[k])
})
- swannodette 12y agoTo be fair `Object.keys()` is relatively recent and still needs to be shimmed for IE < 9. Even so I'd expect the new iterator based (like generators) key, value, and entry iteration to eventually outperform the `Object.keys()` interface that needs to return an array simply to have something to iterate over.
- jonpaul 12y agoTrue. But anyone supporting IE < 9 I'd think would be using ES5 shim: https://github.com/es-shims/es5-shim https://github.com/es-shims/es5-shim But maybe not?