Syntax error Is their JavaScript “not in” operator for checking object properties?

Is their JavaScript “not in” operator for checking object properties?



To get only the else part, just negate, using ! the operator in JavaScript. You can try to run the following code to achieve this −

var arr = {};
if (!(id in arr)) {
}
else {
}

In addition, if you want the existence of a property in an object, then use hasOwnProperty

if (!arr.hasOwnProperty(id)) {
}
else {
}
Updated on: 2020-06-23T11:59:16+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements