I have an object below, that I need in the following format. I can't seem to get the named pairs working. Happily to accept lodash answers as well. Thanks
const object = {
"mobile": "04000000",
"address": "123 fake st"
}
That I need to turn into this format.
const format = [
{
name: "mobile",
value: "04000000"
},
{
name: "address",
value: "123 fake st"
}
]
You can use Object.entries to get the key/value pairs of the object as an array, and Array.map to construct the object for each item:
const object = {
"mobile": "04000000",
"address": "123 fake st"
}
const res = Object.entries(object).map(e => ({name: e[0], value: e[1]}))
console.log(res)