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

  • Home
  • SEARCH
  • 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 7916653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:53:12+00:00 2026-06-03T14:53:12+00:00

Working on a project where I need to add points to an array. Here

  • 0

Working on a project where I need to add points to an array. Here is the code for creating and then trying to add an object to the array:

var points = [];
    points[0] = [];
    points[0][0] = 0; //x-coord
    points[0][1] = 0; //y-coord

points[points.length][0] = x; //Breaks on this line
points[points.length][1] = y;

The exact error I get is Uncaught TypeError: Cannot set property ‘0’ of undefined. This code is run every time a button is pressed and the other values are already ints that are set. I thought that JavaScript allowed you to set values in arrays as you go?

  • 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-03T14:53:14+00:00Added an answer on June 3, 2026 at 2:53 pm

    The last array index is points.length - 1. Now you are addressing an element past the end of array (which is undefined) and trying to assign its “0” property a value of x. Setting properties on undefined is not allowed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on the project and now I need to add a foreign
I'm working on an Android project and I need to add buttons to a
I am currently working on a c# project where I need to add to
I am working on a project and I need to save user configuration. The
I am working on this project where I need to read in a lot
I'm working on a project where I need to get the total row count
I'm working on a project where I need to create a link that when
I'm working on a project that I need to eliminate all references to the
I am working on a project where I need to recursively iterate through the
I am working on a prototype project and need to put a new layer

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.