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

144
Vistas
returning a value if a String includes the key

I have a JS Object Literal (logGroupMap) containing alarm names as keys, and their log groups as values. Alarm names are passed in with consistent names of varying length but with generated characters at the end each time, so I'm trying to see if the string includes a key from the logGroupMap object literal, and if so I want to get the value associated with that key.

  let logGroup = (alarmName) => {
    Object.keys(logGroupMap).forEach((key) => {
      if (alarmName.includes(key)) { logGroup = logGroupMap.key; }
    });
  };

console.log(logGroup(messageDetails.AlarmName));

Currently this is returning undefined in all cases.

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

0

Use the Array.find() method to search for a matching key.

To access a property dynamically, use logGroupMap[key]. logGroupMap.key returns the value of the property named key, it doesn't use key as a variable.

function logGroup(alarmName) {
  let found = Object.keys(logGroupMap).find((key, value) => alarmName.includes(key));
  if (found) {
    return logGroupMap[key];
  }
}

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