I have an enum
export enum A{
X = 'x',
Y = 'y',
Z = 'z'
}
I want this to be converted to
[A.X, A.Y, A.Z]
Type of the array is A[]. How to do this?
You can use Object.keys to get the keys of the enum and use them to get all the values.
It would look something like this.
let arr: A[] = Object.keys(A).map(k => A[k])
You can see it working here.
You can use Object.values to get value of enum
enum A {
X = 'x',
Y = 'y',
Z = 'z'
}
let arr = Object.values(A)
console.log(arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With