This question already has an answer here:
Given a JavaScript object, how can I convert it into an array of objects (each with key, value)?
Example:
var data = { firstName: 'John', lastName: 'Doe', email: 'john.doe@gmail.com' }
resulting like:
[
{ key: 'firstName', value: 'John' },
{ key: 'lastName', value: 'Doe' },
{ key: 'email', value: 'john.doe@gmail.com' }
]
Just make your life easier and use es6 syntax with a map
Or go wild and make the
key
andvalue
keys customizable:An alternative method for doing this that works on multi level objects and does not use recursion.
Using
map
functionInspired By this post