Created
February 5, 2019 23:42
-
-
Save paulomcnally/ff388daf2b8f63bb207cd8a6295327a0 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
| var state = { | |
| items: { | |
| "a": { | |
| location: 1, | |
| enabled: false, | |
| }, | |
| "b": { | |
| location: 2, | |
| enabled: false, | |
| }, | |
| "c": { | |
| location: 3, | |
| enabled: false, | |
| }, | |
| "d": { | |
| location: 4, | |
| enabled: false, | |
| }, | |
| "e": { | |
| location: 5, | |
| enabled: true, | |
| } | |
| } | |
| } | |
| const convert = function(obj) { | |
| let results = []; | |
| const keys = Object.keys(obj) | |
| Object.values(obj).forEach((item, index) => { | |
| item.key = keys[index] | |
| results.push(item); | |
| }); | |
| return results; | |
| } | |
| console.log(convert(state.items)); |
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
| [ { location: 1, enabled: false, key: 'a' }, | |
| { location: 2, enabled: false, key: 'b' }, | |
| { location: 3, enabled: false, key: 'c' }, | |
| { location: 4, enabled: false, key: 'd' }, | |
| { location: 5, enabled: true, key: 'e' } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment