I have this object and I'm trying to convert it.
names = {
animals: ['Dog', 'Cat', 'Snake'],
flowers: ['Rose', 'Daisy']
}
I want to convert it into something like this
newObject = {
type: ['animals', 'flowers']
subtype: ['Dog', 'Cat', 'Snake', 'Rose', 'Daisy']
}
I wrote the following function but for some reason it's not populating correctly.
const newObject = {};
Object.keys(names).map(type => {
newObject['types'] = [...newObject['types'], type];
names[type].map(subtype => {
newObject['subtypes'] = [...newObject['subtypes'], subtype];
})
})