0

I have an object car that contains sub-objects:

var car = {
    bumper: {
        nodes: [[x,y,z],[x,y,z],[...], ... ],
        faces: [[0,1,2],[1,2,3],[...], ... ]
    },

    //more objects

    //references to car parts
    parts: [this.bumper, this.wheel, ... ]
};

The references to these objects are then stored in a car member array parts. Then when I try to access these objects via the parts references in the next function:

var drawParts = function(car.parts)
{
    for(var i = 0; i < car.parts.length; ++i)
    {
        drawFaces(car.parts[i].faces, car.parts[i].nodes);
    }
};

the error occurs in that the expression car.parts[i] is evaluated as undefined.

Could somebody guide me on how to send the bumper object arrays faces and nodes to the drawFaces() function the proper way?

tolerance
  • 11
  • 3
  • Here's a bin of it working. Instead of referencing an array of parts, I added a function that gets all of the nested objects inside of the car object. https://jsbin.com/yapuqupece/edit?html,output – Dustin Stiles Feb 17 '16 at 00:45
  • Note that this will grab all keys off the car, if you're storing meta-data this won't work as nicely. I'm just console.log ing the results out – Dustin Stiles Feb 17 '16 at 00:45

0 Answers0