Skip to content

Instantly share code, notes, and snippets.

@paulomcnally
Created February 5, 2019 23:42
Show Gist options
  • Select an option

  • Save paulomcnally/ff388daf2b8f63bb207cd8a6295327a0 to your computer and use it in GitHub Desktop.

Select an option

Save paulomcnally/ff388daf2b8f63bb207cd8a6295327a0 to your computer and use it in GitHub Desktop.
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));
[ { 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