For example I want to extract an object array from an Enum definition.
Object.keys(HelloWorldEnum).map(el => {
return {
label: HelloWorldEnum[el],
value: el
};
});
enum HelloWorldEnum {
option1 = 'Option1',
option2 = 'Option2',
option3 = 'Option3'
}
Now, how I can do with a function that passing 'HelloWorld' as a variable, below is not work:
getOptions(str) {
return Object.keys([str + 'Enum']).map(el => {
return {
label: [str + 'Enum'][el],
value: el
};
});
}
Even I changed to window[str + 'Enum']
, or this[str + 'Enum']
that it won't works since the Enum definition is not existing in neither window nor this namespace
Assume the above code is in any of an Angular Component