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!
I believe you should try checking down to
modelsUsed
first and see if it even has those 3 items in it first.Try this first
console.log("Engine - Check for modelsUsed: ", this.Engine.attributes.modelsUsed);
then try this
console.log("Engine - usedByMustang: ", this.Engine.attributes.modelsUsed && this.Engine.attributes.modelsUsed.usedByMustang );