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!

23 thoughts on “I need to access an property inside an object but it always comes back as undefined”

  1. 200365 695688I really dont accept this specific post. Nonetheless, I had searched with Google and Ive discovered out that youre right and I had been thinking inside the improper way. Keep on creating top quality material comparable to this. 715141

    Reply
  2. 377628 432666Dude.. My group is not considerably into seeking at, but somehow I acquired to read several articles on your weblog. Its great how intriguing its for me to pay a visit to you fairly often. 11742

    Reply

Leave a Comment