DEV Community

Discussion on: Which is faster: obj.hasOwnProperty(prop) vs Object.keys(obj).includes(prop)

Collapse
 
varoman profile image
varo manukyan

I like testing execution time with console.time(string) and console.timeEnd(string).

Though, as one could guess testing performance this way is a fail. It will give various results every time. You'd better use developer tools instead.

Anyway, Object.hasOwnProperty compared to prop in obj should be incredibly faster as the latter run through all the prototype chain of an object. I've run that tests on small objects and get what I expected.