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

194
Vistas
Not getting nested property value

I have a function to convert units to my native language. My function -

const toCorrectUnitLanguage = (unit, langLocale = 'en') => {
  const savedUnits = {
    sec: { en: 'Sec', bn: 'সেকেন্ড' },
    min: { en: 'Min', bn: 'মিনিট' },
    hour: { en: 'Hour', bn: 'ঘন্টা' },
  }
  if (savedUnits[unit.toLowerCase()]) {
    return savedUnits[unit.toLowerCase()][langLocale];
  }
  return unit;
}

console.log(toCorrectUnitLanguage('sec'))
console.log(toCorrectUnitLanguage('sec', 'en'))
console.log(toCorrectUnitLanguage('sec', 'bn'))

I am getting the correct object when I am logging savedUnits[unit.toLowerCase()]. I am also getting the value I want if I hard code savedUnits[unit.toLowerCase()]["en"]

But I am getting undefined when I am returning savedUnits[unit.toLowerCase()][langLocale]

Any suggestions? Thanks in advance.

Edit: Calling the function like this -

toCorrectUnitLanguage('sec',langLocale)

My node version is 13.14.0. Could that be an issue?

Edit 2: My console.log

if (savedUnits[unit.toLowerCase()]) {
  console.log(savedUnits[unit.toLowerCase()]); //{en: 'Sec', bn: 'সেকেন্ড'}
  console.log(savedUnits[unit.toLowerCase()][langLocale]); //undefined
  return savedUnits[`${unit.toLowerCase()}`][langLocale];
}
about 4 years ago · Santiago Gelvez
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