Check if a property exists in the object or array: `in`
Check if a property exists in the object or array: in
If you have an object and you want to check if a property is present you can use the in
operator.
I think the in
operator is one of the best ways to check the presence of a property because, for example, if you want to check if the value is undefined
, you canβt distinguish the cases if the property doesnβt exist or the property exists and has an undefined value:
The in
operator works also with the arrays. With the arrays, you can check the presence of the numeric index: