I want to check if x
, y
or z
(all string) exists in the Object keys, my longer expression:
if (x in demoObject || y in demoObject || z in demoObject){
// do the following action
}
Is there a shorter and computationally faster way to do it(if can’t achieve both of them at the same code, I want the solution for each side), if I need to check more than 10 values whether they exist in the object keys?
2
Answers
You could take the prototype function
Object.hasOwnProperty
and handover the object asthisArg
.or in your example