I am noticing strange behavior from a javascript object in my Node application. The user object is created by parsing a csv file with two columns: Email and ID. For some reason, I can only access one of the fields using the typical methods. The other field always returns undefined. I am using Node 15.12.0.
When I log the user object, it returns: { 'Email': 'email@example.com', ID: '12345' }
Curiously, the ID field does not have quotes when it is logged, but the Email field does have quotes.
I can access user.ID as usual, but user.Email returns undefined.
console.log(Object.keys(user)); // [ 'Email', 'ID' ]
console.log(user.ID); // 12345
console.log(user.Email); // undefined
console.log(user['Email']) // undefined
console.log(user["Email"]) // undefined
console.log(user.email) // undefined
console.log(user["\'Email\'"]) // undefined
console.log(user["'Email'"]) // undefined
console.log(user[Object.keys(user)[0]]) // email@example.com
console.log(Object.values(user)[0]) // email@example.com
I have tried the using JSON.parse(JSON.stringify(user)), but I get the same results as before.
The only way I can access the Email field is by using the user[Object.keys(user)[0]] or Object.values(user)[0] which is very strange to me.
I would appreciate any ideas you have to figure out whats happening here. Is there something I can do to examine the object more closely? Does the quotes around the keys indicate anything?