Object adding property to subordinate object


#1

Hi there :slight_smile:

while doing the js Modules lessons, I came to a point where I should manually add a property to an object’s object. So my question refers to objects, not the modules the lesssion is actually about.

Lets go directly to the case:

let availableAirplanes = [
{ name: 'AeroJet',
  fuelCapacity: 800
 }, 
{ name: 'SkyJet',
 fuelCapacity: 500
 }
];

According to the solution I should just add a property to the first array (thus object, right?) Element. If every plane would have a name and the capacity as a property, the case would be clear to me:

let availableAirplanes = [
{
aeroJet = {
   name: 'AeroJet',
   fuelCapacity: 800
}
 }
];

Then I could just add a property like availableAirplanes.aeroJet.newProperty = 10; . Which resulted in { aeroJet = { name: 'AeroJet', fuelCapacity: 800 }
This isn’t the case above, as I have no idea to address the first entry and add a property.
Here is where you hopefully come in place :smiley:

please help me out on this question.


#2

Since they’re in an array you could look up what operations are available for that data type


#3

HI, thanks for your hint.

of course that was the first source I browsed through, however a kind of availableAirplanes[0].newProperty=10 did not lead to success either…


#4

Generally if something is “not working” you need to not stop there and instead consider what’s different which will typically tell you a lot about what needs to be changed.

Seems like what you want to do is:

So you’d figure out how to 1) obtain first value of an array 2) add a property to an object
You seem to already have that information


#5

Yeah you were right, thanks a lot @ionatan ! :blush:
I messed around with .push and stuff… but then
availableAirplanes[0].newProp = 'something' made it.