Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7071981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:45:11+00:00 2026-05-28T05:45:11+00:00

Google Chrome is throwing Uncaught TypeError: Cannot set property ‘isDown’ of undefined but it

  • 0

Google Chrome is throwing “Uncaught TypeError: Cannot set property ‘isDown’ of undefined” but it doesn’t look like anything is wrong with my code!

Important part of my variable array:

KEY = {
    UP: 38,
    DOWN: 40,
    W: 87,
    S: 83,
    D: 68
}
pingpong = {
    fps: 60,
    pressedKeys: [],
    complete: false,
}

Key listener initialization (this is where the error is thrown):

    for (var keyCode in KEY) {
        if (KEY.hasOwnProperty(keyCode)) {
            pingpong.pressedKeys[KEY[keyCode]] = {
                isDown: false,
                wasDown: false
            };
        }
    }
    $(document).keydown(function(e) {
        pingpong.pressedKeys[e.which].isDown = true;
    });
    $(document).keyup(function(e) {
/* This line is the issue */    pingpong.pressedKeys[e.which].isDown = false;
    });

Any Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:45:11+00:00Added an answer on May 28, 2026 at 5:45 am

    The problem is that you’re trying to access an element of the pressedKeys array which does not exist. For example, if we pressed the “a” key:

    $(document).keyup(function(e) {
        //Pressed "a" so e.which == 65
        pingpong.pressedKeys[e.which].isDown = false;
    });
    

    When you initialize your array you only create elements for the properties of the KEY object:

    for (var keyCode in KEY) {
        //Iterating over KEY, which contains 5 properties...
        if (KEY.hasOwnProperty(keyCode)) {
            //Add value to pressedKeys (this happens for each of the 5 properties)
            pingpong.pressedKeys[KEY[keyCode]] = {
                isDown: false,
                wasDown: false
            };
        }
    }
    

    So pressedKeys only contains 5 elements, corresponding to the properties of KEY. Note that a TypeError is also thrown in the keydown event handler, as well as keyup.

    To fix it, you could check that e.which is in the KEYS object in the event handler functions. If it’s not, just ignore it. Something like this perhaps (there may be a better way, this is just what came to mind first):

    $(document).keydown(function(e) {
        for(var k in KEY) {
            if(KEY[k] == e.which) {
                break; //Break out of loop and execute last line
            }
            return false; //Key not recognized, last line is not executed
        }
        pingpong.pressedKeys[e.which].isDown = true;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Google chrome gives this javascript error Uncaught TypeError: Object javascript:__doPostBack('ctl00$MainContentPlaceHolder$lnkBtnHidden','') has no method 'click'
Google chrome doesn't behave the same as other browsers when encountering this nugget: <?php
Google Chrome extensions are a nice invention, but they can potentially interact with a
I have begun using Google Chrome as a primary browser, but I miss my
I have problem where google chrome is showing: The site uses SSL, but Google
Google chrome doesn't seem to bother to display an <img> with cross origin src
Google Chrome is set as the default browser. However, it opens links in Firefox,
Google Chrome doesn't seem to have this problem, I noticed this in Firefox. So
Google Chrome has a ChromeDriver available here . I cannot find the equivalent for
Google Chrome and IE8 implement multi-process support for each tab. How would I implement

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.