Skip to content

How to get a key in a JavaScript object by its value?

Let’s take a JavaScript object.

let obj = {
  "First": "A",
  "Second": "B",
  "Third": "C"
}

To find the key of value ‘B’,

let key = Object.keys(obj).find(key => obj[key] == 'B');
console.log(key); //Second

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.