Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
arrayToOptionsObject.js
const HOURS = [
'05', '06', '07', '08', '09', '10', '11', '12',
'13', '14', '15', '16', '17', '18', '19', '20',
'21', '22', '23', '00', '01', '02', '03', '04',
]
/*
* Converts ['05'] to {'05': '05'}
*/
const arrayToOptionsObject = (array => (
array.reduce((obj, value) => {
obj[value] = value
return obj
}, {})
})
<FieldSelect
options={arrayToOptionsObject(HOURS)}
/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment