Skip to content

Instantly share code, notes, and snippets.

@estliberitas
Created February 24, 2015 18:22
Show Gist options
  • Save estliberitas/b9ddb1a491acf40f1714 to your computer and use it in GitHub Desktop.
Save estliberitas/b9ddb1a491acf40f1714 to your computer and use it in GitHub Desktop.
Object to Array using Object.keys and Array#reduce
var o = {
a: 1,
b: 2,
c: 3
};
Object.keys(o).reduce(function(out, key) {
out.push({
key: key,
value: o[key]
});
return out;
}, []); // [{key: 'a', value: 1}, {key: 'b', value: 2}, {key: 'c', value: 3}]
@YuraKolesnikov
Copy link

Cool, but it's still and object, just inside the array.

@thedaviddias
Copy link

Indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment