Why does event[1] return undefined but console.log(event) seems to return an array?

StackOverflow https://stackoverflow.com/questions/22845668

  •  27-06-2023
  •  | 
  •  

سؤال

The console.log return this which looks like and array : keyup charCode=0, keyCode=18 But I tried event[1] to get the keycode but it's undefined, how do I extract the keycode from this ?

function processKeyDown(event)
{
    console.log(event);
}
هل كانت مفيدة؟

المحلول

this is because event is an object, not an indexed based array. use event.keyCode instead.

نصائح أخرى

Use event.keyCode to access the key that was pressed.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top