1

I have this enum:

enum defaultShaderType { VERTEX_SHADER = 23, FRAGMENT_SHADER = 57 } 

Is there a direct way to access the numeric values by ordinal index of an enum in typescript? What I want is for example:

const value1 = defaultShaderType[0]; //23 const value2 = defaultShaderType[1]; //57 

When I try it that I obtain undefined. In my case I want the values in a for loop, so I would like to get the values for the number of elements in the enum. I know there are many workarounds and that can achieve that with other data structures, but can a typescript enum be used this way?

Thanks in advance.

2
  • 1
    Does this answer your question? TypeScript enum to object array Commented Jul 25, 2020 at 20:17
  • it does. If you post it I will accept it. Thanks Commented Jul 25, 2020 at 20:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.