var enums = {
'1': 'HELLO',
'2' : 'BYE',
'3' : 'TATA'
};
I want to be able to convert that into an array that looks like this,
[
{
number:'1',
word:'HELLO'
},
{
number:'2',
word:'BYE'
},
{
number:'3',
word:'TATA'
}
]
all of the solutions I see form an array of either the keys or the values.
You could map the entries with short hand properties.
var enums = { 1: 'HELLO', 2: 'BYE', 3: 'TATA' },
objects = Object.entries(enums).map(([number, word]) => ({ number, word }));
console.log(objects);
.as-console-wrapper { max-height: 100% !important; top: 0; }
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