Skip to content

Instantly share code, notes, and snippets.

@danielstocks
Last active September 4, 2017 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielstocks/7ba37ee763f526b6c482cb971a5d791d to your computer and use it in GitHub Desktop.
Save danielstocks/7ba37ee763f526b6c482cb971a5d791d to your computer and use it in GitHub Desktop.
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