Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

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?

1 Answer

0 votes
by (106k points)

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) 

Related questions

0 votes
1 answer
asked Aug 12, 2019 in Web Technology by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...