DEV Community

Discussion on: An object from two arrays

Collapse
 
savagepixie profile image
SavagePixie

You could also use Object.fromEntries to avoid having to use two separate arrays:

const addKey = str => [ formatKey(str), str ]

const result = Object.fromEntries(fieldValues.map(addKey))
Collapse
 
miteshkamat27 profile image
Mitesh Kamat

Thats great..I should have thought about this. Never mind thanks buddy for this improvisation.