Skip to content

Instantly share code, notes, and snippets.

@chanonroy
Created July 26, 2021 11:07
Show Gist options
  • Select an option

  • Save chanonroy/ac298cbec1a167fbd5a879920c1e2f23 to your computer and use it in GitHub Desktop.

Select an option

Save chanonroy/ac298cbec1a167fbd5a879920c1e2f23 to your computer and use it in GitHub Desktop.
const categories = [
{ id: 1, label: "Action" },
{ id: 2, label: "Romance" },
{ id: 3, label: "Comedy" },
{ id: 4, label: "Horror" },
]
const result = categories.reduce((acc, cur) => {
const { id, label } = cur
acc[id] = label
return acc
}, {})
// result: { 1: 'Action', 2: 'Romance': 3: 'Comedy', 4: 'Horror' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment