Not override spreaded value

I'm exporting some objects:
const PA28_161 = {
...aircraft,
name: 'Piper Warrior PA28-161',
weightMaxTakeoffPounds: 2325,
weightMaxLandingPounds: 2325,
additionalCategories: [
{
name: 'utility',
weightMaxTakeoffPounds: 1950
}
],
masses: [
{
...mass,
name: 'Front Seats',
armInches: 80.5
},
{
...mass,
name: 'Fuel',
armInches: 95,
weightMaxPounds: 2179.45
},
{
...mass,
name: 'Rear Seats',
armInches: 118.1
},
{
...mass,
name: 'Baggage',
armInches: 142.8,
weightMaxPounds: 200
}
]
};

export const default_templates = [
{
...PA28_161,
name: 'OHO YLIL',
masses: [
{
...mass,
name: 'Empty Weight',
weightPounds: 1521.45,
armInches: 86.18
}
]
}
];
const PA28_161 = {
...aircraft,
name: 'Piper Warrior PA28-161',
weightMaxTakeoffPounds: 2325,
weightMaxLandingPounds: 2325,
additionalCategories: [
{
name: 'utility',
weightMaxTakeoffPounds: 1950
}
],
masses: [
{
...mass,
name: 'Front Seats',
armInches: 80.5
},
{
...mass,
name: 'Fuel',
armInches: 95,
weightMaxPounds: 2179.45
},
{
...mass,
name: 'Rear Seats',
armInches: 118.1
},
{
...mass,
name: 'Baggage',
armInches: 142.8,
weightMaxPounds: 200
}
]
};

export const default_templates = [
{
...PA28_161,
name: 'OHO YLIL',
masses: [
{
...mass,
name: 'Empty Weight',
weightPounds: 1521.45,
armInches: 86.18
}
]
}
];
How can I add a mass to masses without overriding the spreaded masses?
4 Replies
Joao
Joao•16mo ago
You can spread the current masses property
masses: [...masses, {}]
masses: [...masses, {}]
Or, push to it upfront:
masses.push({})
masses.push({})
Zach
ZachOP•16mo ago
how the frick did I not think of that 🤣
Joao
Joao•16mo ago
I guess you're technically overwriting it... but with itself so does it count? 🤔
Zach
ZachOP•16mo ago
went with another solution in the end might refactor back to what I had idk
Want results from more Discord servers?
Add your server