Created
February 24, 2015 18:22
-
-
Save estliberitas/b9ddb1a491acf40f1714 to your computer and use it in GitHub Desktop.
Object to Array using Object.keys and Array#reduce
This file contains 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 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}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cool, but it's still and object, just inside the array.