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 8888745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:06:22+00:00 2026-06-14T22:06:22+00:00

The answer to this question seems like it would be obvious, but I’m always

  • 0

The answer to this question seems like it would be obvious, but I’m always looking to improve my semantics, so bear with me.

I have an array structure with individual items containing X,Y coordinates

var example = new Array();
example.push({x:0,y:0});

In my code I have a set interval that updates my canvas and checks for certain conditions. Including one similar to this

if(example[0].x == other.x && example[0].y == other.y)
{
//do something
}

The issue is that the array is very dynamic, and when the code is first executed the example array is empty. Hence, Chrome throws errors along the lines of “Cannot get property x”. To shut up the console, I added a dummy item to the array {x:”~”, y:”~”} but it seems really unintuitive. Have I implemented an undesirable data structure? What’s a simple way to handle if statements for objects that… don’t exist?

  • 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-06-14T22:06:22+00:00Added an answer on June 14, 2026 at 10:06 pm

    Why don’t you just check whether the array has elements?

    if (example.length && ...)
    

    Or whether the first element is true:

    if (example[0] && ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a repeated question but i'm not able to get my answer.
This seems like a silly question but I would really like your comments and
I searched for an answer to this question, but it seems like the only
I apologize if this is a duh question. It seems like the answer should
This seems like a basic question, but I haven't found any clear answers. Essentially,
This seems like it should be fairly straight-forward, but I can't see anything obvious.
I have been trying to find an answer to this question for months, but
This kind of seems like a noob question, but I could not find an
There are many questions like this, but none of them seem to answer my
I've seen many questions like this, but i can't seem to find the answer:

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.