Skip to content

Instantly share code, notes, and snippets.

@auxcoder
Created December 28, 2016 21:37
Show Gist options
  • Save auxcoder/2de2e9140cd6184f8dc17dbf03abe61e to your computer and use it in GitHub Desktop.
Save auxcoder/2de2e9140cd6184f8dc17dbf03abe61e to your computer and use it in GitHub Desktop.
Map over an Object returning a new Array
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