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
Depending on the JS version you are using, you can use the spread operator ...
const getData = data => ({
...data.first && { 'Custom First Prop Name': data.first },
...data.second && { 'Custom Second Prop Name': data.second },
...data.third && { third: data.third },
...data.fourth && { fourth: data.fourth },
});