TypeScript enum to object array

前端 未结 15 2917
不思量自难忘°
不思量自难忘° 2020-12-08 03:38

I have an enum defined this way:

export enum GoalProgressMeasurements {
    Percentage = 1,
    Numeric_Target = 2,
    Completed_Tasks = 3,
    Average_Mile         


        
15条回答
  •  长情又很酷
    2020-12-08 04:17

    There is a simple solution, So when you run Object.keys(Enum) that gonna give you a Array of Values and Keys, in first slice Values and in the second one keys, so why we don't just return the second slice, this code below works for me.

    enum Enum {
       ONE,
       TWO,
       THREE,
       FOUR,
       FIVE,
       SIX,
       SEVEN
    }
    const keys = Object.keys(Enum); 
    console.log(keys.slice(keys.length / 2));
    

提交回复
热议问题