How to check properties on objects in JavaScript?

Check Properties exist

  • Check Properties exist

Syntax:- if (typeof object_name.key !== „undefined‟)

Ex:-

Check Properties exist

  • in operator

Syntax: – if („key‟ in object_name)

Ex:-

Check Properties exist

  • hasOwnProperty ()

Syntax: – if (object_name.hasOwnProperty(“key”))

Ex:-

Tagged : / / / /

Leave a Reply