add checks for hasOwnProperty and used forEach where useful

when Object.prototype is modified (or Array.prototype, for that matter), we can no longer iterate over the keys (or elements, respectively) using `for (var ... in ...)`. Added a hasOwnProperty check for object key iteration, and used `.forEach` for array element iteration instead.
Basically checking length is apparently expensive so you need to cache it in a local variable or loop backwards. Also `obj[key] !== undefined` is faster than `obj.hasOwnProperty(key)`