I want to get a enum from object, in typescript, is it possible? Example below!
const keys = ['a', 'b', 'c', 'd', 'e']
const values = [1, 2, 3, 4, 5]
// expected result
enum result {
a = 1,
b = 2,
c = 3,
d = 4,
e = 5
}
I want to get a enum from object, in typescript, is it possible? Example below!
const keys = ['a', 'b', 'c', 'd', 'e']
const values = [1, 2, 3, 4, 5]
// expected result
enum result {
a = 1,
b = 2,
c = 3,
d = 4,
e = 5
}
No you can not get an enum, which is a pre-defined type.
What you are trying to get is a mapping between the two arrays (dictionary/object), you can create it dynamically if they are always in the correct order.
const keys = ['a', 'b', 'c', 'd', 'e']
const values = [1, 2, 3, 4, 5]
// mapping
let dictionary = {};
keys.forEach((key, i) => dictionary[key] = values[i]);
console.log(dictionary);