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?
points = []; points[0] = {x: 0, y: 0};