Languages
[Edit]
EN

JavaScript - check if key exists in object

0 points
Created by:
Saim-Mccullough
688

In this article, we would like to show you how to check if key exists in object working with JavaScript.

Quick solution:

 

Practical example

Edit

In this example, we use for...in statement to check if a key exists in the object. This way true value is returned even when the key value is undefined.

Alternative solution

Edit

You can also use hasOwnProperty() method to achieve the same result as above.

See also

Edit
  1. JavaScript - for...in statement

References

Edit
  1. for...in - JavaScript | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join