As always, there are multiple ways to solve this problem. In this tutorial, we are going to explain one of the simplest methods to access a key name by its value.
In the following example, we are going to enter a text in the input element and upon click of a button, we want to find its corresponding key in the object and display it on the screen. Please have a look over the code example and steps given below.
HTML & CSS:
We have 4 elements in the HTML file (div, input, button, and h1). The div element is just a wrapper for the rest of the elements.
We have done some basic styling using CSS and added the link to our style.css stylesheet inside the head element.