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

142
Views
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 answers
Answer question

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 Report
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!