Sometimes, we want to check if a key exists in a JavaScript object.
In this article, we’ll look at how to check if a key exists in a JavaScript object.
How to check if a key exists in a JavaScript object?
To check if a key exists in a JavaScript object, we can use the in
operator.
For instance, we write
const testArray = "key1" in obj;
to check if property with name 'key1
‘ is in the obj
object.
Conclusion
To check if a key exists in a JavaScript object, we can use the in
operator.