Skip to content

How to get key of a enum. #21

Closed
Closed
@Rj-s

Description

@Rj-s

I have one situation here :-

Below is my enum:-

export const ColorCodes = Enum({
  ES_IN_1: 'RED',
  ES_IN_2: 'YELLOW',
});

Now i get a string code dynamically from server :- 'ES_IN_1' or 'ES_IN_2' .
I need to compare this string code with enum and need to implement custom code. something like this:-

const serverCode  = 'ES_IN_1';

if(serverCode == ColorCodes.ES_IN_1.toString()){
    ...... custom code.
}else if(serverCode == ColorCodes.ES_IN_2.toString()){
   ....... custom code.
}

The problem is how would i get key of this ColorCodes.ES_IN_1 'which is ES_IN_1'.
I dont see something toString() or getKey() here which could resolve this issue.

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions