window.addEventListener('keydown', (e) => {
let arrowsObj = {
"ArrowUp": 1,
"ArrowDown": 2,
"ArrowLeft": 3,
"ArrowRight": 4
}
let eventKey = e.key;
console.log(arrowsObj.eventKey);
});
Despite performing the necessary checks, the code above is not functioning as expected. Here are the checks made:
arrowsObj.hasOwnProperty(eventKey)
if(eventKey in arrowsObj)
Both of the checks returned true, so what could be causing the issue? Is it perhaps related to data type?
Your insights will be greatly appreciated!