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

187
Vistas
How can I best optimize my angular function?

I need your help, I have a code and I need to optimize it, can anyone know how this could be? This is my code:

handlerChangeInfo(value, fieldName: string) {
if (fieldName === 'fullName') {
  this.billingFields.full_name = value;
}
if (fieldName === 'address') {
  this.billingFields.address = value;
}
if (fieldName === 'postalCode') {
  this.billingFields.postal_code = value;
}
if (fieldName === 'city') {
  this.billingFields.city = value;
}
if (fieldName === 'stateOrProvince') {
  this.billingFields.state_or_province = value;
}
if (fieldName === 'taxId') {
  this.billingFields.tax_id = value;
}

}

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can create an object to map your field name values to the object key names

const obj = {
  fullName: 'full_name',
  address: 'address',
  postalCode: 'postal_code',
  city: 'city',
  stateOrProvince: 'state_or_province',
  taxId: 'tax_id'
}


handlerChangeInfo(value, fieldName: string) {
   if (obj[fieldName]) {
      this.billingFields[obj[fieldName]] = value;
   }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Map version

const obj = new Map([
   ['fullName', 'full_name'],
  ['address', 'address'],
  ['postalCode', 'postal_code'],
  ['city', 'city'],
  ['stateOrProvince', 'state_or_province'],
  ['taxId', 'tax_id']
]);

handlerChangeInfo(value, fieldName: string) {
   if (obj.get(fieldName)) {
      this.billingFields[obj.get(fieldName)] = value;
   }
}
about 4 years ago · Juan Pablo Isaza Denunciar
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