I would like to know how to convert enum object to array of objects in javascript
It works, but am getting the output with four object arrays instead of two object arrays
const result = Object.entries(countries).map(([value, key]) =>
({ country: value.toLowerCase(), id: key })
);
enum countries {
SINGAPORE = 123,
DENMARK = 246
}
Actual Output:
[
{country: '123', id: 'singapore'}
{country: '246', id: 'denmark'}
{country: 'singapore', id: 123}
{country: 'denmark', id: 246}
]
Expected Output:
[
{country: "singapore", id: 123},
{country: "denmark", id: 246}
]