I need to access an property inside an object but it always comes back as undefined

I’m using Javascript inside a React component.

I want to access a certain property of an object.

So if I write this object out to the console like this:

console.log("Engine: ", this.Engine);

I get this:

Engine:
        child { ... }
          attributes:
               id: 293
               manufactureer: "Ford"
               date: "2012-02-18"
               location: "Michigan"
               modelsUsed:
                  usedByMustang: true
                  usedByF150: true
                  usedByFusion: false
               source: "f9919"
               typeName: "Coyote"

If I write out something like this: console.log("Engine Type Name: ", this.Engine.attributes.typeName);

I get this: Engine Type Name: Coyote

That’s great, but I just want to check one property buried deep down, the one called usedByMustang that’s inside the modelsUsed array.

So I tried all these:

console.log("Engine - usedByMustang: ", this.Engine.attributes.usedByMustang);
console.log("Engine - usedByMustang: ", this.Engine.attributes.modelsUsed.usedByMustang);
console.log("Engine - usedByMustang: ", this.Engine.attributes.modelsUsed[0]);

They all come back as undefined

Is there a way to access the properties I want?

Thanks!

Leave a Comment