Created
December 28, 2016 21:37
-
-
Save auxcoder/2de2e9140cd6184f8dc17dbf03abe61e to your computer and use it in GitHub Desktop.
Map over an Object returning a new Array
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 data = { | |
| '0': 'Some content', | |
| '1': 'Another content', | |
| '2': 23 | |
| }; | |
| var newArray = Object.keys(data).map(function(key, index) { | |
| return {label: index + 1, value: data[key]}; | |
| }); | |
| // newArray = [{label: 1, value: 'Some content'}, { label: 2, value: 'Another content'}, {label: 2, value: 23}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment