Created
July 26, 2021 11:07
-
-
Save chanonroy/ac298cbec1a167fbd5a879920c1e2f23 to your computer and use it in GitHub Desktop.
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 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