Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
How to exclude fields from const conditionally

I have a const in JSON format which I fill with user input and pass to another function. Let's say this is my const:

const body = {
   title: enteredTitle,
   desc: enteredDesc,
   "costs": {
      price: enteredPrice,
      tax: enteredTax
   }
}

with the "entered" values being user inputted values.

I would like to have a way to exclude these fields entirely if the user input is blank. So if they don't input a price for example, the body would then be {title: ..., desc: ..., costs: {tax: ...}} or if they don't input a desc then {title: ..., costs: {price: ..., tax: ...}} and so on.

How can I achieve this? The only way I can think of is to have some map filtering when I'm actually using the body, but if there's a more elegant way to exclude these values directly in the const before passing it on, I would prefer that.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!