I ran into an issue with my app earlier today, when I was trying to conditionally render elements based on whether or not a value exists in an enum. Here is the simplified code:
enum Enum {
'id',
'name',
'age'
}
['id', 'name', 'age'].forEach((val) => {
console.log('in enum: ', !!Enum[val])
})
This prints,
"in enum: ", false
"in enum: ", true
"in enum: ", true
I ended up doing something like,
. . .
if (!!Enum[val] && val === 'id') {
// code
}
. . .
Am I missing something? Is id some sort of reserved value for enums?