Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • According to the code in the question, there isn't a 2D array (or map/dictionary as an object) of cells, so var cellMatch = cells[ x2 ][ y2 ] won't retrieve anything. Assuming cells is a simple 1D array of cellMatch objects, then the code would retrieve an item at a random index in that array (since it's unlikely they'd be index by the coordinates) and then attempt to get a property of that cellMatch which is another number. And cellMatch doesn't have numeric properties, so the result will be either undefined or an error if x2 is out of bounds of the array. Commented Mar 26 at 10:43
  • @VLAZ The OP say: "After gathering the data into an array of cellData objects", this leads me to believe that cells is an array of CellData objects,... Commented Mar 26 at 10:54
  • you say: "and then attempt to get a property of that cellMatch which is another number. And cellMatch doesn't have numeric properties, so the result will be either undefined or an error if x2 is out of bounds of the array", CellData has three attributes: x, value, and y. Are they numeric? I don't know, and it doesn't matter in this context. On the other hand, if, as you suggest, x2 or y2 don't “stay within the matrix boundaries”... we'd have to take the glass of wine away from the OP :) Commented Mar 26 at 10:56
  • "has three attributes: x, value, and y. Are they numeric? I don't know" it makes no difference what the values are. The property *names are what you listed. data[ y2 ] is not going to match any of them because y2 is a number. Therefore data[ 42 ] will return undefined for any data = { x: <anything>, y: <anything>, value: <anything> }. Commented Mar 26 at 11:16
  • "this leads me to believe that cells is an array of CellData objects" yes - an array of objects, sure. But it doesn't follow that it's a 2D array indexed by the x/y coordinates of the object. So, it's very likely going to look like this: [ new cellData(1, "foo", 2), new cellData(4, "bar", 2) ]. Trying to fetch arr[4][2] from there is an error. Fetcing arr[1][2] is undefined. Commented Mar 26 at 11:18