-2

I am working in react. I have a constant like

const priorityMap = {
 "medium":"clean",
 "high":"breaker",
 "low":"promote"
}

If I do the following , I am getting result.

const map1 = priorityMap["medium"];
console.log("print checkgroup  " + map1)

But I want to do the reverse thing. My input is "clean" and I want to retrieve "medium". Is there any way to fetch the key?

devserkan
  • 16,870
  • 4
  • 31
  • 47
Rhea
  • 381
  • 1
  • 7
  • 22

1 Answers1

0

It would be :

const valueToSearch = "clean"
const result = Object.entries(priorityMap).find(entry => entry[1] === valueToSearch)[1]