3

The following code iterates through a click event, logging its properties. However, it seems that the event "hides" properties other than "isTrusted" resulting a false when calling hasOwnProperty

document.body.addEventListener("click",(e)=>{
    for(var i in e){
        console.log(e.hasOwnProperty(i),i);
    }
});

Log:

true "isTrusted"
false "screenX"
false "screenY"
false "clientX"...

Same thing is when you call Object.keys(e) the result is only the "isTrusted" property.

["isTrusted"]

Why is that? is there a way, other than for...in loop to list the event properties and values?

Roni Gadot
  • 437
  • 2
  • 19
  • 30
  • duplicate of https://stackoverflow.com/questions/59235864/object-keyskeyboardevent-only-get-one-istrusted-key-rather-than-all-keys – A Kareem Nov 07 '21 at 18:47
  • Does this answer your question? [Object.keys(KeyboardEvent) only get one "isTrusted" key rather than all keys](https://stackoverflow.com/questions/59235864/object-keyskeyboardevent-only-get-one-istrusted-key-rather-than-all-keys) – A Kareem Nov 07 '21 at 18:48

0 Answers0