How do I check if an object has a specific key in JavaScript?

Asked 2 years ago, Updated 2 years ago, 78 views

Which of these is the right way?

if (myObj['key'] == undefined)

if (myObj['key'] == null)

if (myObj['key'])

javascript object

2022-09-22 14:33

1 Answers

Try writing the in operator in JavaScript. if ('key' in myObj)


2022-09-22 14:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.