I want to create a dropdown from enum data type but when I try to change enum into object with name and value; enum array return twice of the enum member. using a function from this SO post
Typescript: v 2.3.3
Angular v 4.3.4
ps. can not update typescript version dues to angular version. below is the relevant code
export enum FrequencyEnum {
H1 = <any>'1 Hour',
H12 = <any>'12 Hours',
D1 = <any>'24 Hours',
D7 = <any>'7 Days',
M1 = <any>'1 Month',
M3 = <any>'3 Months',
CD = <any>'Custom Date Range'
};
export interface Frequency {
name: string;
value: string;
range?: { from: string; to: string; };
}
export function enumSelector(definition) {
console.log('definition: ', definition);
return Object.keys(definition)
.map(key => ({ value: definition[key], name: key }));
}
this.frequnecyList = enumSelector(FrequencyEnum);
it gives array of 14 objects
[
{
"value": "1 Hour",
"name": "H1"
},
{
"value": "H1",
"name": "1 Hour"
},
{
"value": "12 Hours",
"name": "H12"
},
{
"value": "H12",
"name": "12 Hours"
},
{
"value": "24 Hours",
"name": "D1"
},
{
"value": "D1",
"name": "24 Hours"
},
{
"value": "7 Days",
"name": "D7"
},
{
"value": "D7",
"name": "7 Days"
},
{
"value": "1 Month",
"name": "M1"
},
{
"value": "M1",
"name": "1 Month"
},
{
"value": "3 Months",
"name": "M3"
},
{
"value": "M3",
"name": "3 Months"
},
{
"value": "Custom Date Range",
"name": "CD"
},
{
"value": "CD",
"name": "Custom Date Range"
}
]
how can I get only 7 value ( equal to enum member) in the final array?