Explore Courses Blog Tutorials Interview Questions
0 votes
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
Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.5k questions

29.9k answers


99.1k users

Browse Categories