-2

I've a problem getting object keys by value for example:

issues: {
  window_expired: 'Yes',
  no_power: 'No',
  no_display: 'Yes'
}

I want to get object keys which have 'Yes' Value as: window_expired, no_display

I've tried this method which is working but it's returning the 1st key i want to loop through and get the keys by value:

function getKeyByValue(object, value) {
  return Object.keys(object).find((key) => object[key] === value);
}

1 Answers1

0

you should use filter in your case.

Object.keys(issues).filter(e => issues[e] === 'Yes')

Have a good day

Andy
  • 189
  • 2
  • 13