Reputation: 31
In the project i am working on we have this widely used enum:
export enum A{
Document = '1',
Person = '2',
Organization = '3',
Equipment = '4',
Location = '5',
Event = '6',
Link = '7',
Target = '8',
}
Example: I want to get Organization
with A['3']
Upvotes: 0
Views: 3262
Reputation: 2814
Object keys
enum A {
Document = '1',
Person = '2',
Organization = '3',
Equipment = '4',
Location = '5',
Event = '6',
Link = '7',
Target = '8',
}
console.log(Object.keys(A)[Object.values(A).indexOf("1")]);
Upvotes: 2
Reputation: 49985
You can use Object.entries to do that:
enum A{
Document = '1',
Person = '2',
Organization = '3',
Equipment = '4',
Location = '5',
Event = '6',
Link = '7',
Target = '8',
}
const param = '3';
const value = Object.entries(A).find(([_, v]) => v === param)![0];
Upvotes: 1