Back
How do I check if a particular key exists in a JavaScript object or array?
If a key doesn't exist, and I try to access it, will it return false? Or throw an error?
For checking if a key exists in a JavaScript object you can use in operator see the following code:-
"key" in obj
To check if a key doesn't exist, parenthesis is must use:
!("key" in obj)
31k questions
32.8k answers
501 comments
693 users