-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
  • 15,490
  • 4
  • 29
  • 45
Rhea
  • 331
  • 5
  • 20

1 Answers1

0

It would be :

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