question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: How can I retrieve an enum member by value?

See original GitHub issue

Say for example I have this enum:

var Members = new Enum({
  A: "a",
  B: "b"
});

I’d like to be able to do something like:

var member = Members.byValue('a');

Did I miss something in the documentation, or is this currently impossible?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ColinRhodescommented, Aug 13, 2015

What is the reason for not allowing strings as values? I see this as a pretty common use case. In my system, use strings as values so that they are human-readable in the database. This means that in addition to wanting to use strings as values, I’d also be looking for an option to have a constructor option that changes the behaviour of toString/toJSON to return the value rather than the key.

0reactions
adraicommented, Aug 15, 2015

Try to do a pull request…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get int value from enum in C# - Stack Overflow
In the Questions class I have a get(int foo) function that returns a Questions object for that foo . Is there an easy...
Read more >
Twenty C# Questions Explained, 15, How do I get the string ...
Twenty C# Questions Explained, 15, How do I get the string value of an enum · Key moments. View all · Key moments...
Read more >
enum in Java - GeeksforGeeks
Enums are used when we know all possible values at compile time, such as choices on a menu, rounding modes, command-line flags, etc....
Read more >
How To Use Enums in TypeScript - DigitalOcean
You can declare enum members to have string values with the following ... Get help and share knowledge in our Questions & Answers...
Read more >
Enum Types - Java™ Tutorials
An enum type is a special data type that enables for a variable to be a set of predefined constants. The variable must...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found