Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda