I am having trouble trying to append something my object, using the spread syntax.
Depending on the fact whether the NewPerson is there for a private/professional occasion I want to append additional key/values to the object/array.
Somehow it does not work. Hopefully someone can help me out. :(
var NewPerson = [
Firstname: this.state.addPersonFirstname,
Lastname: this.state.addPersonLastname,
Birthday: this.state.addPersonBirthday,
Occasion: this.state.addPersonOccasion,
];
if (this.state.addPersonOccasion === 'OccasionProfessional') {
NewPerson = [
...NewPerson,
...[ProfEmployerName: this.state.addPersonOccasionProfEmployerName],
...[ProfEmployerPLZ: this.state.addPersonOccasionProfEmployerPLZ],
...[ProfEmployerCity: this.state.addPersonOccasionProfEmployerCity],
...[ProfEmployerUVT: this.state.addPersonOccasionProfEmployerUVT]
]
}
if (this.state.addPersonOccasion === 'OccasionPrivate') {
NewPerson = [
...NewPerson,
...[PrivPersonStreet: this.state.addPersonOccasionPrivPersonStreet],
...[PrivPersonPLZ: this.state.addPersonOccasionPrivPersonPLZ],
...[PrivPersonCity: this.state.addPersonOccasionPrivPersonCity]
]
}
var CombinedPersons
if (PreviousPersons === null) {
CombinedPersons = NewPerson
} else {
CombinedPersons = [...PreviousPersons, ...NewPerson]
}
[]with object braces{}. The code that follows it is completely off as well since you're struggling to understance the difference. Lemme rewrite that.