Created
July 4, 2022 16:45
-
-
Save crshmk/7a5ac549c970ece6ace0b960fe602f9f to your computer and use it in GitHub Desktop.
a cleaner Object.entries api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapObj = (fn, obj) => | |
Object.entries(obj).map(([key, value]) => { | |
return fn(value, key) | |
}) |
Author
crshmk
commented
Jul 4, 2022
const obj = {
one: 1,
two: 2
}
const makeOptions = (value, key) => ({ label: key, value })
mapObj(makeOptions, obj)
// [
// { label: 'one', value: 1 },
// { label: 'two', value: 2 }
// ]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment