I'm working on a small API and I want to update the data using HTTP PATCH REQUEST
without using a bunch of if statements. I'm trying to fill the outgoing data object with the changed data only.
update() {
let prop1 = hasBeenChanged.prop1 ? changedData.prop1 : null;
// ...
let propN = hasBeenChanged.propN ? changedData.propN : null;
let data: ISomething = {
// something like --> property != null ? property: property.value : nothing
}
}
Is there any way to create the data object dynamically?
See Question&Answers more detail:os