OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can I get a key in a JavaScript 'Map' by its value?

  • Thread starter Thread starter Engineer Passion
  • Start date Start date
E

Engineer Passion

Guest
I have a JavaScript 'Map' like this one

Code:
let people = new Map();
people.set('1', 'jhon');
people.set('2', 'jasmein');
people.set('3', 'abdo');

I want some method to return a key by its value.

Code:
let jhonKey = people.getKey('jhon'); // jhonKey should be '1'

<p>I have a JavaScript 'Map' like this one</p>
<pre><code>let people = new Map();
people.set('1', 'jhon');
people.set('2', 'jasmein');
people.set('3', 'abdo');
</code></pre>
<p>I want some method to return a key by its value.</p>
<pre><code>let jhonKey = people.getKey('jhon'); // jhonKey should be '1'
</code></pre>
 

Latest posts

Top