Is the use of this construct considered a bad practice in JavaScript and could it lead to unexpected behavior?
if (e.target.name in {name: '', number: ''}) {
// do something
}
This code checks if the 'name' attribute of an HTML node exists in the keys of the "object" and proceeds if it does. It's a basic check to see if the clicked element is one we need. How does it compare performance-wise to something like this?
if(['name','number'].some(a=>a==e.target.name)) {
// do something
}
What is the optimal way to perform these checks both in terms of typing and performance?